Approach :
store the given number into some other variable then reverse the number and compare it with stored no. If both the numbers are same then the given number is palindrome.
Example :
Given No Reversed No Equal Palindrome
123 321 No No
121 121 Yes Yes
————————————————————————————————————————————————————————–
C code to check whether given number is palindrome or not.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#include<stdio.h> void palindrome(int n){ int revno=0,r,s=n; while(n>0){ r=n%10; revno=revno*10+r; n=n/10; } if(revno==s) printf(" %d is a palindrome number",s); else printf(" %d is not a palindrome number",s); } int main() { int n; printf("Enter the number :"); scanf("%d",&n); palindrome(n); return 0; } |
Code provided by Lalit Kumar