Problem: Write a C program to check whether a number is a Palindrome or not.

Palindrome number is that number which when reversed, is equal to the original number.

Examples: 111, 121, 8008 etc.

palindrome number

Steps to Check Palindrome in C:

  1. Input a number.
  2. Run while loop with condition (number != 0)
  3. Divide the number by 10
  4. Store the remainder into another variable reverse as stated reverse = reverse *10 + remainder
  5. Update the number as number = number/10
  6. After the loop ends, check if reverse == original_number
  7. If yes, then the number is palindrome else not.

Here is the implementation of the steps in C.

#include <stdio.h>
#include <stdlib.h>
 
int main()
{
    int original_number, number, remainder, reverse =0;
 
    printf("Enter a Number \n");
    scanf("%d",&original_number);
 
   
    //By copying original_number we are keeping it safe from changes
    number = original_number ;
 
    while(number != 0){
        remainder = number % 10;
        reverse = reverse * 10 + remainder;
        number = number / 10;
    }
 
    if(original_number == reverse)
        printf("Palindrome \n");
    else
        printf("Not Palindrome \n");
 
    return 0;
}

Output

When the input number is 456.

Palindrome number in C

When the input number is 121.

Palindrome number C program

In this tutorial, we learned what is palindrome number and how to check palindrome number in C programming language.

Leave a Reply

16 − 14 =