Tuesday, 29 July 2014

C# Palindrome Code

Sample code for Palindrome  in C#.


    class Program
    {
        static int strLen = 0;
        static int numLen = 0;
        static void Main(string[] args)
        {
            string InuputString = "Testset";
             Console.WriteLine(InuputString);
             ISPalindrome(InuputString);
        }

        public  static void ISPalindrome(string str)
        {

            strLen = str.Length;
            str = str.ToLower();

            while (numLen < strLen)
            {

                if (str[numLen] != str[strLen - 1])
                {
                    Console.WriteLine("Not a Palindrome");
                    break;
                }

                else
                {
                    numLen++;
                    strLen--;

                    if (numLen > strLen - 1)
                    {
                        Console.WriteLine("Palindrome");
                    }

                }

            }
        }
    }




No comments:

Post a Comment