Palindrome
Palindrome
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Palindrome
{
class Program
{
static void Main(string[] args)
{
int flag=0;
Stack<char> s = new Stack<char>();
Console.WriteLine("Enter the length of the string");
int n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the string");
string word = Console.ReadLine();
for (int i = 0; i < n; i++)
{
s.Push(word.ElementAt(i));
}
for(int i=0;i<n;i++)
{
if (s.Peek().CompareTo(word.ElementAt(i))!=0)
{
flag=1;
Console.WriteLine("Not a palindrome");
break;
}
s.Pop();
}
if(flag==0)
Console.WriteLine("is a palindrome");
Console.ReadLine();
}
}
}