DotNet Mirror
  DNM facebook   DNM Google+   DNM Twitter   

.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) : 9526  (Professional)
Location : INDIA
Home Page : http://dotnetmirror.com
About : I am admin of this site.
Rate this resource
 
Add your Comment
Name Email WebSite
Captcha Refresh


Comments (2)
 
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.

 
2. By Ranjan on 20 Sep 2015

Why you are calculated in length of number because after you can't use the lengthofnumber variable!!!

 
cheap jordans|wholesale air max|wholesale jordans|wholesale jewelry|wholesale jerseys