Palindrome string program in C#

A palindrome is a string such that if you reverse it, it will not change. The string should be remain same and meaning also remain same.

Example of Palindrome string:

Mom, Malayalam, Wow, Deleveled, etc.

Program of palindrome string in c# console application


    static bool IsPalindrome(string src)
        {
            bool palindrome = true;
            for (int i = 0; i < src.Length / 2 + 1; i++)
            {
                if (src[i] != src[src.Length - i - 1])
                {
                    palindrome = false;
                    break;
                }
            }
            return palindrome;
        }
 
          static void Main(string[] args)
        {
            Console.Write("ENTER A STRING :- ");
            string s = Console.ReadLine();
            if (IsPalindrome(s) == true)
            {
                Console.WriteLine(s + " IS A PALINDROME");
            }
            else
            {
                Console.WriteLine(s + " IS NOT A PALINDROME");
            }
        }
	

Output

	
   ENTER A STRING :- MOM
   MOM IS A PALINDROME.
           

Post Your Comment