C Program to find sum of two numbers



#include<stdio.h>
#include<conio.h>
void main()
{
int number,d,num,pal,reverse=0;
clrscr();
printf("Enter a number:");
scanf("%d",&number);
num=number;
while(num>0)
{
d=num%10;
num=num/10;
reverse=reverse*10+d;
}
if(number==reverse)
{
printf("%d is a palindrom number",number);
}
else
{
printf("%d is not a palindrom number",number);
}
getch();
}

Explanation:

The above program will print that whether the given number is palindrome or not. The program takes an integer value from user and assigns that value in the variable 'number' and further it assigns a number one-less than the value present in number variable in another variable num. While loop will be executed till the num does not become less than 0.In the loop we will find the reverse of the given number. If the reverse is equal to given number then the number is a palindrome number otherwise not. We can understand this process by following example:

number=121,reverse=0
num=number=121
num>0,True
iteration 1:
d=121%10=1
num=121/10=12
reverse=reverse*10+d=0*10+1=1
num>0,True iteration 2:
d=12%10=2
num=12/10=1
reverse=1*10+2=12
num>0,True
iteration 3:
d=1%10=1
num=1/10=0
reverse=12*10+1=121
num>0,false
loop break..
number=reverse=121 so number 121 is a palindrome number.
The output of the above program is given below:

Output:

c program