DotNet Mirror
  DNM facebook   DNM Google+   DNM Twitter
search left
Thanks for visiting! | Join Us
search right

.NET program to check the number is palindrome or not

By Ashok Nalam on 25 Dec 2012 | Category: C# | Tagged: palindrome number 
In this snippet we will write a program to check whether the given number is palindrome number or not.
  Discuss Add Comment   |  
Add rating Rate this resource   

What is palindrome Number?

"Palindrome number is a number that remains the same when its digits are reversed"

Example:

Number 151 - palindrome number.
Number 152 - Not a palindrome number.

Program:

class PalindromeNumberOrNot
{
public static void Main()
{
Console.WriteLine("********** Palindrome Number Check Example ********");
Console.WriteLine("Enter Number to Want to check");
int numberToCheck = int.Parse(Console.ReadLine());
int lenthOfNumber = numberToCheck.ToString().Length;
double reminder = 0;
double sum = 0;
int tempNo = numberToCheck;
while (tempNo > 0)
{
reminder = tempNo % 10;
sum = sum * 10 + reminder;
tempNo = tempNo / 10;

}
if (sum == numberToCheck)
{
Console.WriteLine("The given Number {0} is a Palindrome Number", numberToCheck);
}
else
{
Console.WriteLine("The given Number {0} is NOT a Palindrome Number", numberToCheck);
}
}
}

output:

Input =151 (palindrome Number)



Input =152 (Not a palindrome Number)


Some of palindrome numbers are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101, 111, 121, 131, 141, 151, 161.......

  Discuss Add Comment    
Add rating Rate this resource   
About the Contributor
Member Since : 10 Dec 2012
Member Points (Level) : 5963  (Expert)
Location : INDIA
Home Page : http://dotnetmirror.com
About : I am admin of this site.
Rate this resource
 
Advertisement
Add your Comment
Name Email WebSite


Comments (1)
 
1. By Karna Vasamsetti on 28 Dec 2012

We can convert the number into string and write a small program to find out is it a palindrome or not.That's a bit easy process and takes less time/memory for execution.