programming-examples/c/_Basic/C Program to Reverse a Number & Check if it is a Palindrome.c

27 lines
735 B
C
Raw Normal View History

2019-11-15 12:59:38 +01:00
/*
* C program to reverse a given integer number and check
* whether it is a palindrome. Display the given number
* with appropriate message
*/
#include <stdio.h>
void 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");
}