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) : 6453  (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
Captcha Refresh


Comments (22)
 
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!!!

 
3. By Barnypok on 28 Dec 2016

2aHuST http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
4. By Barnypok on 28 Dec 2016

bQap8K http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
5. By Barnypok on 28 Dec 2016

AQSo6R http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
6. By Barnypok on 28 Dec 2016

C4OYbf http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
7. By Barnypok on 29 Dec 2016

1nUYqF http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
8. By Barnypok on 29 Dec 2016

XTT1a4 http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
9. By Barnypok on 29 Dec 2016

SdHT3n http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
10. By Barnypok on 31 Dec 2016

B3HI3O http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
11. By Barnypok on 02 Jan 2017

vUguKR http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
12. By Barnypok on 02 Jan 2017

8lsQ0J http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
13. By Barnypok on 02 Jan 2017

FRuxTK http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
14. By Barnypok on 02 Jan 2017

PGks0E http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
15. By Barnypok on 05 Jan 2017

u1sdWe http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
16. By Barnypok on 06 Jan 2017

oVqyCc http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
17. By Barnypok on 06 Jan 2017

Xo2Xvt http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
18. By Barnypok on 08 Jan 2017

W6CC4k http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
19. By Barnypok on 08 Jan 2017

5Vo2oE http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
20. By Barnypok on 08 Jan 2017

tlAn63 http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
21. By Barnypok on 08 Jan 2017

WyKE7T http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
22. By Barnypok on 08 Jan 2017

XJ1ov0 http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com