Subscribe Us

Palindrome Number In C

 

Palindrome Number In C

C Program To Check Palindrome number or Not

A Palindromic number (Also Known As a Numeral Palindrome or a Numeric palindrome)
is a number (such as 12321) that remains the same when its digits are reversed

Example :
Given Number : 121
It is a Palindrome Number
Since:
121 remains the same, when its digits are reversed
Example :
Given Number : 123
It is Not a Palindrome Number
Since:
123 do Not remain the same, when its digits are reversed

Algorithm To check if a number is a palindrome or not
you can use the following algorithm:
  1. Read the input number.
  2. Create a copy of the input number.
  3. Initialize a variable to store the reverse of the number, initially set to 0.
  4. While the input of the number is not equal to 0, perform the following steps:
    • Get the last digit of the number by using the modulo operator (%).
    • Multiply the reverse variable by 10 and add the last digit to it.
    • Divide the input number by 10 to remove the last digit.
  5. Compare the copy number with the reverse variable.
  6. If they are equal, the number is a palindrome; otherwise, it is not.
  7. Print the result.

In this algorithm, the input number is processed to reverse its digits by repeatedly extracting
the last digit of the number, multiplying the reverse by 10, and adding the last digit to it.
Then, it checks if the reverse is equal to the input number to determine if it is a Palindrome Number.

Please note that this implementation assumes that the input number is a non-negative integer.
You may need to add additional checks for negative numbers or other cases depending on your
requirements.

Here is an example implementation in C:

Source Code

// C Program To Check Palindrome number or Not ?
#include<stdio.h>
#include<conio.h>
   void main()
      {
        int num , Rd , Rev = 0 , ncopy ;
        printf("Enter a number To Check : ");
        scanf("%d",&num);
        ncopy=num;
        while( num!=0 )
            {
               Rd  = num % 10 ;
               Rev = Rev * 10 + Rd ;
               num = num / 10 ;
            }
        if( Rev==ncopy )
           printf("It is a Palindrome Number . ");
        else
           printf("It is Not a Palindrome Number . ");
        getch();
      }

Output

Sample Input :
Enter a Number To Check : 121
Sample Output:
It is a Palindrome Number

Sample Input :
Enter a Number To Check : 124
Sample Output:
It is Not a Palindrome Number

Sample Input :
Enter a Number To Check : 13231
Sample Output:
It is a Palindrome Number

This algorithm takes an input number and reverses it using the modulus operator and division.
It then compares the copy number with the reversed number to determine if it is a palindrome or not.

Variable Description
Data Type Variable NameDescription
intnumTo Store an Integer That You Want To Check
intRdTo Store Last Digit of the Number During Loop
intRevTo Store Reversed Number
intncopyTo Store Copy of Input Number

Looping Related Programs