Search For

Palindrome check

Flag Hide Line Nos
Flagging a Snippet, takes the snippet to Moderator Attention;


0
The program explains palindrome check for a input string.
If the string and the reverse of the string are equal then they are in palindrome.

Palindrome string examples:
MADAM
VADAV

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string initial = "";

            Console.WriteLine("Enter a String to check for Palindrome");

            string input = Console.ReadLine();

            int iLength = input.Length;

            if (iLength == 0)
            {
                Console.WriteLine("You did not enter the string");

            }

            else
            {

                for (int j = iLength - 1; j >= 0; j--)
                {
                    initial = initial + input[j];
                }

                if (initial == input)
                {
                    Console.WriteLine(input + " is palindrome");
                }
                else
                {
                    Console.WriteLine(input + " is not a palindrome");
                }


                Console.Read();
            }
        }
} 
        }
    



Output:
Enter a String to check for Palindrome
MADAM
MADAM is palindrome


Enter a String to check for Palindrome
RAJAN
RAJAN is not a palindrome




..
Vote! You feel this code is working like charm ? Go a head Login and Press up arrow.
Didn't work ?, press down arrow and let us know the error in comments

Comments