Thursday, 21 August 2014

C Program to check the number is palindrome or not

 C Program to check the number is palindrome or not

This C Program to check the number is palindrome or not,  first  reverses a number. Then it checks if
given number and reversed numbers are equal. If they are equal, then its a palindrome.
Here is source code of the C Program to check the number is palindrome or not. The C program is successfully compiled and run on a Linux system and windows system. The program output is also shown below.
#include <stdio.h>

int main()
{
int num, temp, remainder, reverse = 0;

printf("Enter an integer \n");
scanf("%d", &num);
/* original number is stored at temp */
    temp = num;
while (num > 0)
{
        remainder = num % 10;
        reverse = reverse * 10 + remainder;
        num /= 10;
}
printf("Given number is = %d\n", temp);
printf("Its reverse is = %d\n", reverse);
if (temp == reverse)
printf("Number is a palindrome \n");
else
printf("Number is not a palindrome \n");
return 0;
}

Output 1












Output 2