1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
static void Main(string[] args) { Console.Write("Enter something for to check that is it palindrome :"); string text = Console.ReadLine(); int len = text.Length; bool flag = true; //check palindrome for (int i = 0; i < len/2; i++) { if (text[i] != text[len - (i + 1)]) { flag = false; break; } } //if flag true, text is palindrome if (flag) { Console.WriteLine("{0} is palindrome", text); } else { Console.WriteLine("{0} is not palindrome", text); } Console.ReadLine(); } |
1