C Program to Check Palindrome Number

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:-

  1. If-Else
  2. While loop

Kindly go through this Topic with above-provided link.

2. Algorithm

Here’s the Algorithm of C program to check for palindrome number.

  1. START
  2. Take input of number from user.
  3. Using while loop check the given number is greater then 0 or not.
  4. Extract the last digit of number using the modulus also called Remainder.
  5. Add the Remainder digit in a new variable ‘rev’.
  6. Remove the last digit by using division operator.
  7. At the last check the original number and reversed number using If-Else statement.
  8. 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:

groot
groot

Leave a Reply

Your email address will not be published.