Reverse of a three digit number and check for palindrome

C program to find the reverse of a three digit number and then check whether it is a palindrome number or not.

A palindromic number is a number that remains the same when its digits are reversed. For example, 121, 363, 1441, 12421, etc.

Program

#include<stdio.h>
#include<conio.h>
void main()
{
	int number,o,t,h,revnum;

    printf("\nEnter a three digit number\t:");
    scanf("%d",&number);

    o=number%10;
    h=number/100;
    t=(number/10)%10;
    revnum = (o*100) + (t*10) + h;
    printf("\nReverse of a number is\t:%d",revnum);
    if(number==revnum)
    {
        printf("\nIts a palindrome number");
    }
    else
    {
        printf("\nIt is not a palindrome number");
    }

    getch();
}

Output

********** Run1 **********

Enter a three digit number      :123

Reverse of a number is  :321
It is not a palindrome number


********** Run2 **********

Enter a three digit number      :121

Reverse of a number is  :121
Its a palindrome number

Explanation

To check whether a number is a palindrome number or not, first we have to extract the individual digits of the number. Then, we will reverse the number.
If original number and reversed number, both are same, then it is a palindrome number. If not, then, it is not a palindrome number.

To extract the digits, following expressions are used:
o=number%10;
h=number/100;
t=(number/10)%10;
where, 'number' variable is used to store the value of the number entered by the user. ones, tens, and hundreds digits of the number are extracted and stored in 'o', 't' and 'h' variables respectively.

To calculate the reverse of the number, following formula is used.
revnum = (o*100) + (t*10) + h;
where, 'revnum' is the variable used to store the reverse number.

Next step is to compare the reversed number with the original number.
if(number==revnum)
If, above condition evaluates to true, then, the number is a palindrome number. Else, the number is not a palindrome number.