TASK-
Write a C program for Palindrome number.
What is a Palindrome number: Number which when reversed is equal to the original number. For example:
121, 12321, 1001 etc.
CODE:
#include<stdio.h>
int main(){
int num,reverse=0,d,original;
printf("Enter the number ");
scanf("%d",&num);
original=num;
// saved value of num in original because as we move in loop we will lose the value of num !
while (num!=0)
{
d=num%10;
reverse=(reverse*10)+d;
num/=10;
}
if (original==reverse) // reverse is the number which we got after loop and operation on logic
printf("\n%d is a Palindrome number",original);
else
printf("\n%d is not a Palindrome number",original);
getchar();
return 0;
}
EXPECTED OUTPUT:
Nice work! Keep it up 💪
ReplyDelete