using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace palindrome
{
class Program
{
static void Main(string[] args)
{
int i;
string str = Console.ReadLine();
char[] arr = str.ToCharArray(); // converting string to array
char[] arr1 = new char[arr.Length];
// now reverse an array using for loop
for (i = 0; i < arr.Length; i++)
{
arr1[arr.Length - 1 - i] = arr[i];
}
// converting an array to string
string result = new string(arr1);
if (result == str)
{
Console.WriteLine("Given String is a palindrome");
}
else
{
Console.WriteLine("Given String is not a palindrome");
}
Console.ReadLine();
}
}
}
No comments:
Post a Comment