Program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int num, rem, rev = 0;
Console.WriteLine("//How to check a number palindrome or not in c# ?");
Console.WriteLine("Enter A number :");
num = Convert.ToInt32(Console.ReadLine());
if (num > 0)
{
for (int temp = num; temp != 0; temp /= 10)
{
rem = temp % 10;
rev = rem + (rev * 10);
}
if (rev == num)
Console.WriteLine("The number " + num + " is a palindrome number .");
else
Console.WriteLine("The number " + num + " is not a palindrome number .");
}
else
Console.WriteLine("Enter A valid Number :\n");
Console.ReadKey();
}
}
}
Output :
//How to check a number palindrome or not in c# ?
Case 1:
Enter A number :
151
The number 151 is a palindrome number .
Case 2:
Enter A number :
12345
The number 12345 is not a palindrome number .
Comments
Post a Comment