Palindrome String Program in C#
Advertisements
Palindrome String Program in C#
To check string is palindrome or not first reverse string if resultant string is same like original string then it is palindrome string other wise nor palindrome.
Palindrome String Program in C#
using System; namespace palindrome { class Program { static void Main(string[] args) { string s,revs=""; Console.WriteLine(" Enter string"); s = Console.ReadLine(); for (int i=s.Length-1; i>=0; i--) //String Reverse { revs += s[i].ToString(); } if (revs == s) { Console.WriteLine("String is Palindrome"); } else { Console.WriteLine("String is not Palindrome"); } Console.ReadKey(); } } }
Output
Enter any String: Hello String is not a palindrome
Output
Enter any String: Mam String is palindrome
Google Advertisment