Palindrome Or Not
Palindrome or not:-
In the C programming, the palindrome number check is done to check whether the variable inserted by the user is equal to the original number. This C program reverses the number (inserted by the user) with the help of while loop. After that, ‘if’ condition is applied to test if the reversed number is equivalent to the original digit or not.
Algorithm to check whether a number is palindrome or not:
Step 1: Start
Step 2: Prompt the user to insert a number
Step 3: Store the number in temporary variable
Step 4: Reverse the number
Step 5: Compare the temporary number with the reversed number
Step 6: If both the numbers are same, print the palindrome number
Step 7: Else printf “not palindrome number”
Step 8: Exit
Read Also: Program for Perfect Number or Not
Program to check whether a number is palindrome or not:
#include<stdio.h> int main() { int n,r,sum=0,temp; printf("insert a num="); scanf("%d",&n); temp=n; while(n>0) { r=n%10; sum=(sum*10)+r; n=n/10; } if(temp==sum) printf("palindrome num "); else printf("not a palindrome"); return 0; }
Output
Insert a num: 151 Palindrome num
Insert a num: 5621 Not a palindrome num