C Program to Check Whether a Number is Palindrome or Not

A number is Palindrome if the reverse of that number is equal to the original number.
Example. 
      consider a number 12321, where reverse of it is 12321, which is equal to the original number. Hence 12321 is a Palindrome number.
Note that all single digit numbers are Palindrome.

% is the remainder after division (modulo division) arithmetic operator in C.
11 % 5 = 1 (11 / 5 = 2 with remainder 1)

/*C Program to Check Whether a Number is Palindrome or Not*/
#include <stdio.h>
int main()
{
    int n, rev = 0, temp, num;
    printf("Enter an integer: ");
    scanf("%d", &n);
    num = n;

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

    // check if reversed number is equal to original number
    if (num == rev)
        printf("%d is a palindrome.", num);
    else
        printf("%d is not a palindrome.", num);

    return 0;
}
$ gcc palindrome.c
$ ./a.out
Enter an integer: 123
123 is not a palindrome.
$ ./a.out
Enter an integer: 12321
12321 is a palindrome.
$ ./a.out
Enter an integer: 1
1 is a palindrome.
$ ./a.out

Enter an integer: 33
33 is a palindrome.
$

also see

C Programming language
Go Programming language
Linked List Array
Simplification Queue
DBMS Reasoning
Aptitude HTML
Previous articleLab Course – HTML
Next articleArmstrong Number in C

LEAVE A REPLY

Please enter your comment!
Please enter your name here