C LAB‎ > ‎(Sem1) Introduction to C‎ > ‎

WAP to check if number is Palindrome or not.

posted Nov 6, 2010, 1:06 AM by Neil Mathew   [ updated Nov 6, 2010, 1:23 AM ]

SOURCE CODE:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
 
 main()
{
 
int num;    //number inputted by user
int n;     //temporary storage
int rev=0; //stores the reverse of that number
int digit; //stores the individual digits 
 
printf(" Enter the number to check if it's Palindrome or not: ");
scanf("%d", &num);
 
n=num;
 
do
{
digit=n%10;
rev=(rev*10)+digit;
n=n/10;
}
while(n>0);
 
if(rev==num)
{
printf("\n The number is a palindrome. ");
}
else
{
printf("\n The number is not a palindrome. ");
}
 
}


OUTPUT:

 Enter the number to check if it's Palindrome or not: 121

 The number is a palindrome. 
 Enter the number to check if it's Palindrome or not: 153

 The number is not a palindrome. 

Comments