Check whether a number is palindrome or not in C

05 min read

C program to check whether the given number is a palindrome or not is explained below. A palindrome is a number which when reversed gives the same result as it is before the reversal. In simple, it means that original number is equal to reversed number.

#include <stdio.h>
int main()
{
int n, reversedInteger = 0, remainder, originalInteger;
printf("Enter an integer: ");
scanf("%d", &n);
originalInteger = n;
while( n!=0 )
 {
 remainder = n%10;
 reversedInteger = reversedInteger*10 + remainder;
 n /= 10;
 }
 if (originalInteger == reversedInteger)
 printf("%d is a palindrome.", originalInteger);
 else
 printf("%d is not a palindrome.", originalInteger); 
 return 0;
}

 

Output

Enter an integer: 1001 1001 is a palindrome.
POST A NEW COMMENT
     
  • Input (stdin)

    Output (stdout)


    Input (stdin)

    Your Output (stdout)

    Expected Output

    Compiler Message

    Input (stdin)

    2    3

    Your Output (stdout)

    5

    Expected Output

    5

    Compiler Message

    5

    Error