forked from dscgecbsp/Hacktoberfest-2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpalindrome_number.c
23 lines (23 loc) · 957 Bytes
/
palindrome_number.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*A program to check whether a number is palindrome or not.
An integer is a palindrome if the reverse of that number is equal to the original number.
Eg:- 121. Reverse of 121 is also 121. Hence, 121 is a palindrome number
*/
#include <stdio.h>
int main()
{
int num, reverse=0, rem;
printf("Enter a number : ");
scanf("%d",&num);
int n = num;//storing the number in another variable because the number would reduce to 0 after computing
while(n != 0)
{
rem = n % 10;//extracting the last digit and storing it in rem
reverse = reverse * 10 + rem;//formula to reverse the digits of a number
n /= 10;//reducing the number of digits by 1 from the units place by dividing the number by 10
}
if(reverse == num)//checking if the reversed number is the same as the number entered
printf("%d is a palindrome number\n",num);
else
printf("%d is not a palindrome number\n",num);
return 0;
}