This program reverses an integer number. Palindromes are those numbers whose values is same if you read it from left to right or right left. So if a number and its reverse is same it is a palindrome.
Here we divide the number with 10 and extract the remainder. This remainder is always the digit in the unit place of the number. The quotient is again divided with 10, and this continue till the quotient falls below 0. The remainder extracted in each division by 10 is added to form the reverse number.
-
//Program to reverse a number and check weather it is palindrome or not
-
-
#include<stdio.h>
-
main()
-
{
-
int rem,n,dup,rev=0;
-
scanf("%d",&n);
-
dup=n;
-
for(; n>0; n/=10)
-
{
-
rem=n%10;
-
rev=(rev*10)+rem;
-
}
-
if(rev==dup)
-
else
-
}
-