0% found this document useful (0 votes)
26 views1 page

Palindrome

palindrome

Uploaded by

Alice Martin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views1 page

Palindrome

palindrome

Uploaded by

Alice Martin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

using System;

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();
}
}
}

You might also like