# Palindrome Number Program in C

Palindrome number program in C. Here, we will develop the palindrome number program in C. The palindrome number is based on Reverse of a number. We will also find the palindrome number in the given range.

Palindrome number:- If the Reverse of a number is equal to the same number then the number is called a palindrome number. Example:-
5225 = 5225 So, 5225 is a palindrome number.
123 = 321 So, 123 is not a palindrome number.

## Palindrome program in C using while loop

While loop in C is a pre-test loop where the expression is evaluated then only statements are executed. It uses a test expression to control the loop. Before every iteration of the loop, the test expression is evaluated.

``````#include<stdio.h>
int main()
{
int number, remainder, sum=0 ;
int temp;

printf("Enter the number : ");
scanf("%d", &number);

temp = number;

while( number!=0 )
{
remainder = number % 10;
sum = sum*10 + remainder;
number /= 10;
}

if ( sum == temp )
printf("%d is a palindrome number.\n",temp);
else
printf("%d is not a palindrome number.\n",temp);

return 0;
}``````

Output:-

Enter the number: 123
123 is not a palindrome number.

Enter the number: 5225
5225 is a palindrome number.

In this program, we take four variables `number`, `remainder`, `sum`, and `temp`. The variable `number` stores the input integer value. The variable `sum` is initialized with 0. Variable `temp` is used to store the number value temporarily.

Later we used this temp variable to compare the resulting sum. To check number is a palindrome number or not, first we need to reverse the number. The `%` operator gives the last digit of a number and `/` operator removes the last digit of the number. Using these operators number is reversed.

Now, it is compared with temporarily stored value using if-else statement. If condition is true then it is palindrome number otherwise it is not palindrome number.

## C program to Find palindrome number in a given range

``````#include<stdio.h>
int main()
{
long a, b, n, reverse;

printf("Enter n value: ");
scanf("%ld",&n);

for(a=1;a<=n;a++)
{
reverse = 0;
for(b=a; b!=0; b/=10)
{
reverse = reverse *10 + b%10;
}

if(a==reverse) printf("%ld\t",a);
}

return 0;
}``````

Output:-

Enter n value: 100
1 2 3 4 5 6 7 8 9 11 22 33 44 55 66 77 88 99

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!