Thursday 25 July 2013

Palindrome program in c#.net.

In this Article , I have explained palindrome program in c#. This program is generally asked in interview.

What is palindrome.

Answer:- Palindrome means when you reverse the string or number then the reversed string or number is equal to original string or number.

Program:-


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

namespace Consoleprogram
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Please enter the string");
            Program pgrm = new Program();
            string a=Console.ReadLine();
            pgrm.palindrom(a);
            Console.ReadKey();
        }
        public string palindrom(string str)
        {
            //str = Console.ReadLine();
            string s=string.Empty;
            int strLenght = str.Length;
            for (int i = strLenght-1; i >=0; i--)
            {
                s = s + str[i];
            }
            if (s == str)
            {
                Console.WriteLine("Entered string is Palindrom.");
            }
            else
            {
                Console.WriteLine("Entered String is not palindrom.");
            }
            return str;
        }
    }

}