**Palindrome number in c** is to check whether the number is palindrome or not.

In this tutorial we are going to see what is palindrome number, How to check that number is palindrome number in c.

**What is Palindrome number ?**

Any number which remains same when we reverse it.

for example : **121**, **212**, **12321 **

as we see if we reverse these numbers still all numbers remains same.

**Logic to check Palindrome number in c :**

For this first we take a number from user. we reverse the given number. after that we compare both given and reversed number if both are equal then number is palindrome number otherwise not.

**Example :**

number = 121

reverse number = 121

Number is palindrome.

**Concept you should know from c :**

**Algorithm :**

- Start
- Declare variables
- Take number from user
- Reverse the given number
- Compare both numbers
- if both equal then print palindrome number
- End

**Program to check palindrome number in c**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#include <stdio.h> int main() { int n, reverse = 0, t; printf("Enter a number to check if it is a palindrome or not\n"); scanf("%d", &n); t = n; while (t != 0) { reverse = reverse * 10; reverse = reverse + t%10; t = t/10; } if (n == reverse) printf("%d is a palindrome number.\n", n); else printf("%d isn't a palindrome number.\n", n); return 0; } |

**Output :**

**Explanation :**

**First include preprocessor directives stdio.h in program.****Next write main function from where the execution of the program begins.****Declare the variables int n, reverse = 0, t; n => to store number user enters, reevverse => to store reverse of given number, t is temporary variable.**- next we copy the given number into temporary variable.
**t = n;** - Now we perform the reverse of the given number mathematically. for this we use while loop. while (t != 0) which is used to traverse the number till end.
**Now the main logic comes here**let the number ‘n’ be 321 and as 321>0, while loop gets executed

then x=321%10—>which is 1.

rev=0*10+1——–>1

n=321/10———>32

The rev for the first loop execution is rev=1.

**Now the number ‘n’ has become ’32’ and n>0, while loop executes for the 2nd time.**then x=32%10—>which is 2.

rev=1*10+2——–>12

n=32/10———>3

The rev when loop executed the second time is rev=12.

**Now the number ‘n’ has become ‘3’ and n>0, while loop executes for the 3rd time**then x=3%10—>which is 3.

rev=12*10+3——–>123

n=3/10———>0

The rev when loop executed the third time is rev=123.

**Now as the number of variable ‘n’ is 0 which is not n>0 then the loop terminates.Then the final reverse is ‘123’.****Now compare reverse and given number.****If both Re equal pint number is palindrome else not.****End.**

## Leave a Reply