You must Sign In to post a response.
  • Category: .NET

    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
  • #18176
    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

    Regards,
    Venkatarajan A

    BEEN THERE. DESTROYED THAT.


This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.