26 July 2011

palindrome in console applications


string str = string.Empty;
            Console.WriteLine("Enter a String");
            string s = Console.ReadLine();
            int i = s.Length;
            for (int j = i - 1; j >= 0; j--)
            {
                str = str + s[j];
            }
            if (str == s)
            {
                Console.WriteLine(s + " is palindrome");
            }
            else
            {
                Console.WriteLine(s + " is not a palindrome");
            }

No comments: