C Program to find the palindrome of given number

C Programming C Programming Code Example

C Program to find the palindrome of given number

Problem:
Write a C program to find the palindrome of a given number.

C Program to find the palindrome of given number

Solution:
Logic for palindrome number:
  1. Take the number and put it in a temp variable
  2. Reverse the number
  3. Check the number if that was the taken number or not
  4. If that are the taken number,  then it is palindrome number
So, to reverse a number in c with appropriate logic, see the above code’s explanation:
C Code for palindrome number:

#include <stdio.h>

int main()
{
int n, reverse = 0, temp;

printf("Enter a number to check if it is a palindrome or not = n");
scanf("%d",&n);

temp = n; // Put the number in seperate because we check the number after getting the reverse

while( temp != 0 )
{
reverse = reverse * 10;
reverse = reverse + temp%10;
temp = temp/10;
}

if ( n == reverse ) // n was the first taken number and check with the new reverse number
printf("%d is a palindrome number.n", n);
else
printf("%d is not a palindrome number.n", n);

return 0;
}
Run C Code for palindrome number in Live: [Give input like 121]

So, we’ve checked the number if it is palindrome or not. Having any problem, just comment here.

Tags:
C Program to find the palindrome of given number, palindrome number, palindrome, c code for palindrome , reverse and palindrome a number

Leave a Reply

Your email address will not be published.