Palindrome Number in C Programming.
What will be the programming for Palindrome number in C programming?
What is Palindrome Number?
Palindrome Number are such number when we reverse its digit its remain same. Such number are called Palindrome Number. Means when we reverse digit of a number then it will be equal to that original number.
Example:- 101 when we reverse its digit then it will became 101 and both number are same so 101 is Palindrome Number. But when we take another number 102 and reverse its digit then its become 201 and both number are not equal or same so 102 is not a Palindrome Number.
Programming:-
#include<stdio.h>
#include<conio.h>
int main()
{
int num, sum = 0, temp, count; //Data type deceleration.
printf("Enter any number to check ether it is Palindrome number or not");
scanf("%d",&num); //User input
temp = num;
while(temp > 0) // Loop for finding Palindrome number
{
count = temp %10;
sum = (sum * 10) + count;
temp = temp / 10;
}
if(sum == num) //Checking whether number is palindrome or not
{
printf("%d is a Palindrome number",num);
}
else
{
printf("%d is not a Palindrome number",num);
}
getch();
return 0;
}
Output:-
Fig:-1
Fig:-2
Logic:-
As the definition of the Palindrome Number we have to reverse the digit of that number and compare with original number that both are equal or not. For that I have taken a temporary variable which contain the value of original number and all the logical stuff are done with that temporary variable. And by using while we reverse the digit of that number . With help of If else condition we are able to compare it with the original variable.
If you face any problem then comment in comment section or visit my YouTube Video and watch the video to understand the logic. Videos are in Hindi language.
good 1
ReplyDelete