You must Sign In to post a response.

c# - palindrome program

The forum thread has not been reviewed by Editors yet. Readers are advised to use their best judgement before accessing this thread.
This thread will be reviewed shortly.
If you think this thread contain inappropriate content, please report to webmaster.
hi
if anyone can write a program to check for a palindrome?
eg:malayalam,madam
srini


Comments

Author: Brainstorming Guy11 May 2005 Member Level: Gold   Points : 2

Hai,
You can use this piece of code


using System;

class MyString
{
public static void Main()
{
Console.WriteLine("Is 'rotator' PalinDrome:{0}",IsPalindrome("rotator"));
Console.WriteLine("Is 'visualc#' PalinDrome:{0}",IsPalindrome("visualc#"));
}

// Function to Test for Palindrome
public static bool IsPalindrome(String strParam)
{
int iLength,iHalfLen;
iLength=strParam.Length-1;
iHalfLen=iLength/2;
for(int iIndex=0;iIndex<=iHalfLen;iIndex++)
{
if(strParam.Substring(iIndex,1)!=strParam.Substring(iLength-iIndex,1))
{
return false;
}
}
return true;
}

}

Hope it helps you a bit.
If you have any queries, please feel free to post here.
Happy Coding!!!

Regards,
Brainstorming Guys


Sign In to post your comments