Check Palindrome Number from a string
static void Main(string[] args)
{
Console.WriteLine(" Enter string");
string s = Console.ReadLine();
Console.WriteLine(PalindromNo(s));
Console.ReadLine();
}
public static string PalindromNo(string str)
{
string strOut = string.Empty;
string revs = string.Empty;
if (!string.IsNullOrEmpty(str))
{
for (int i = str.Length-1; i >= 0; i--)
{
revs += str[i].ToString();
}
if (revs == str)
{
strOut = "YES";
}
else
strOut = "No";
}
else
strOut = "Enter a string to check palindrom";
return strOut;
}
Comments
Post a Comment