Latest Post

Tuesday, 3 January 2017

Program in C# to check srting is a Palindrome or not

Write a program in C# to Check Whether a String Palindrome is or not.

Following is the simple C# code :
class Lab
    {
        static void Main(string[] args)
        {
            string InputString, reverseString = "";
            Console.WriteLine("Enter any string");
            InputString = Console.ReadLine();
            for (int i = InputString.Length - 1; i >= 0; i--)
            {
                reverseString += InputString[i].ToString();
            }

            if (reverseString == InputString)
            {
                Console.WriteLine("String is Palindrome\n\n");
                Console.WriteLine("Entered String was {0} and reverse string is {1}", InputString, reverseString);
            }
            else
            {
                Console.WriteLine("String is not Palindrome\n\n");
                Console.WriteLine("Entered String was {0} and reverse string is {1}", InputString, reverseString);
            }
            Console.ReadKey();

        }
    }

Output:-
Enter any string

MADAM

String is Palindrome
Entered String was MADAM and reverse string is MADAM


Government Jobs