The Palindromes are numbers that read the same forward as backward. For example, 5885, 78587, 32823 and etc...
C# program to check a Number is Palindrome or Not:
using System;
namespace PalindromeCheck
{
class Program
{
static void Main(string[] args)
{
// Declaration
var sum = 0;
// Get input parameter
Console.Write("Enter the Number: ");
var input = int.Parse(Console.ReadLine());
// Assign the value to temp variable
var temp = input;
// Logic to check the number is Palindrome or not
while (temp > 0)
{
var r = temp % 10;
sum = (sum * 10) + r;
temp = temp / 10;
}
if (input == sum)
Console.Write("Number is Palindrome.");
else
Console.Write("Number is not Palindrome");
Console.ReadKey();
}
}
}
Output:
Enter the Number: 5885
Number is Palindrome.
Enter the Number: 1235
Number is not Palindrome
Comments (0)