Palindrome Number-A palindrome number is a type of number that when reversed is the same as the original number.
In this C Programming Example, we will take input from the user and check whether the given number is Palindrome or not.
Example-
INPUT
Input number-242
OUTPUT
The number given by the user is a palindrome.
Before writing this C program, let’s go through the concept we are gonna use in our program for Palindrome Number.
1. Concept
For creating a C program we have to go through the steps given below:
- First, we have to take the input of the number from the user which we have to check for palindrome.
- Then we will extract(take out) its digits from last and store them in a new variable.
- After extracting its digits, we will remove the digit from the original number.
- We will keep the digits adding in a new variable created.
- In the last step, we will compare the original number with a reversed number using the If-Else condition.
The concept of C programming you need to learn before writing the program is:-
Kindly go through this Topic with above-provided link.
2. Algorithm
Here’s the Algorithm of C program to check for palindrome number.
- START
- Take input of number from user.
- Using while loop check the given number is greater then 0 or not.
- Extract the last digit of number using the modulus also called Remainder.
- Add the Remainder digit in a new variable ‘rev’.
- Remove the last digit by using division operator.
- At the last check the original number and reversed number using If-Else statement.
- STOP
3. C Program to check Palindrome Number
After going through the algorithm now we will take a look on the code below.Take input from user and move on to the C program.
#include<stdio.h>
#include<conio.h>
int main()
{
int number,rev=0;
int remainder;
printf("Enter the number which u want to check for Palindrome: ");
scanf("%d",&number);
int num=number;
while(number>0)
{
remainder=number%10;
rev=rev*10+remainder;
number=number/10;
}
if(num==rev)
printf("given number is palindrome");
else
printf("given number is not palindrome");
getch();
return 0;
}
4. Output
Here’s the output of the above C Program to check Palindrome Number:
