Problem: Program to check whether given number is palindrome or not.
Process: First find the reverse of a given number, N, and compare reverse number and given number if equals then it is Palindrome else not.
#include<stdio.h>
int main() {
int num, reverse=0, temp;
scanf("%d",&num);
temp = num;
while(temp!=0){
reverse = reverse * 10 + temp % 10;
temp /= 10;
}
if(num==reverse){
printf("Palindrome");
}else{
printf("Not");
} return 0;
}
int main() {
int num, reverse=0, temp;
scanf("%d",&num);
temp = num;
while(temp!=0){
reverse = reverse * 10 + temp % 10;
temp /= 10;
}
if(num==reverse){
printf("Palindrome");
}else{
printf("Not");
} return 0;
}
Sample Input1
2024
Sample Output1
Not Palindrome
Sample Input2
2002
Sample Output2
Palindrome
2024
Sample Output1
Not Palindrome
Sample Input2
2002
Sample Output2
Palindrome