Check string is a palindrome or not

Sumank
Posted by Sumank under C# category on | Points: 40 | Views : 1624
static void Main(string[] args)
{
string Str = null;
Console.WriteLine("Enter string");
Str=Console.ReadLine();
bool chk = true;
for (int i = 0; i <= Str.Length/2 + 1; i++)
{
if (Str[i] != Str[Str.Length - i - 1])
{
chk = false;
}
}
if(chk==true)
Console.WriteLine("Plaindrome");
else
Console.WriteLine("Not Plaindrome");
}

Comments or Responses

Posted by: Vinay9995 on: 5/21/2013 Level:Starter | Status: [Member] | Points: 10
in the 9th line code a small modification needs to be done
i.e, if(str[i]!=str[str.length-i-1]) you forgot to place i

Login to post response