Here in this program, we will code to check whether an entered number is a palindrome number or not. let's discuss the Palindrome Program in C.
Palindrome Program in C
What is a Palindrome number?
A palindrome number is a special number because it remains the same when its digit gets reversed. For example, 16461 is a palindrome number if you reverse this number still, we get 16461. By default, all the 1-digit numbers are palindrome numbers.
Statements we will use in this program
- While loop
- % (arithmetic modules)
- If…else statement
Logic
- First, we will ask the user to enter a number
- Then using a while loop we will try to reverse the entered number using % and other athematic operation
- At last, we will compare the reversed number with the entered number
- If the number match, we will print the number is a palindrome if not we print its not a palindrome number.
Palindrome Program in C
#include<stdio.h>
int main()
{
int num,x, y=0,rev;
printf("Enter a Number: ");
scanf("%d",&num);
rev= num;
while(rev!=0)
{
x= rev%10;
y=x+(y*10);
rev=rev/10;
}
if(num==y)
printf("%d is a palindrome number",num);
else
printf("%d is not a palindrome number",num);
}
Output:
Enter a Number: 14641 14641 is a palindrome number
Conclusion
Checking a palindrome number in C is very easy. The only logic it tasks is reversing the number that we want to check for palindrome. And to reverse a number in C we can use the simple logic where we keep dividing the number by 10 until its quotient becomes 0, which can be achieve with this algorithm
while(rev!=0) { x= rev%10; y=x+(y*10); rev=rev/10; }
People are also reading:
- WAP in C++ and Python to find the greatest number among the three numbers
- WAP to Find Cube of a Number using Functions
- WAP in C++ & Python to Insert an Element in an Array
- WAP to print given series:1 2 4 8 16 32 64 128
- WAP in C to Check Whether the Number is a Prime or not
- WAP to Print the Following Triangle
- WAP in C to calculate the factorial of a number
- WAP to print the truth table for XY+Z
- WAP to find quotient and remainder of two numbers
- Most Asked Pattern Programs in C
Leave a Comment on this Post