Subscribe to:
Post Comments (Atom)
CodeShikhi - The World for Programmers, প্রোগ্রামিং,Learn Programming,Learn Javascirpt | C | C++ | Python | OOP,Learn Programming in Bangla,Bangla Programming Tutorial,Leetcode Problem Solution,BEE Problem Solution,C Programming in Bangla,C in Bangla,Javascript tutorials,C Programming Bangla Tutorial, URI Online Judge Solution in C C++ Python,JavaScript Full Tutorials , OOP Tutorial in C++, Object Oriented Programming in C++,Learn OOP in C++,C Programming Exercise,C Programming Example with Code
#include<stdio.h>
int main()
{
int dummy,n,rev=0,x;
printf("Enter a number\n");
scanf("%d",&n);
dummy=n;
while(n>0)
{
x=n%10;
rev=rev*10+x;
n=n/10;
}
if(dummy==rev) {
printf("The given number %d is a palindrome\n",rev);
} else {
printf("The given number %d is not a palindrome\n",rev);
}
}
A palindrome number is a number that is same after reverse. For example, 121, 34543, 343, 131, 48984 are the palindrome numbers.
This is same as reversing a number. To print reverse of a number, just we used dummy variable to check whether the reversed number is same as the original one(i.e. 'n').
for example if n=321=dummy then the reverse rev=123.
As dummy is not equal to rev then the output is not a palindrome.(Here we can't use 'n' as it become 0 at the end of the loop which is why we are using a variable 'dummy' for temporary storage of the value).
Previous Post:
0 Response to C Program to Check Number is Palindrome or Not | C Programming Examples
Post a Comment