C Program to find sum of two numbers



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

Explanation:

The above program will print that whether the given number is Armstrong 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 check the sum of cubes of individual digits of the given number. If the sum of cubes of individual digits of given number is equal to the number itself then the number will be an Armstrong number otherwise not. We can understand this process with the help of given example:

number=153,arm=0
num=number=153
number>0,True
iteration1:
d=153%10=3
number=153/10=15
arm=0+3*3*3=27
number>0,True
iteration 2:
number=15%10=5
number=15/10=1
arm=27+(5*5*5)=152
number>0,True
iteration 3:
number=1%10=1
number=1/10=0
arm=152+(1*1*1)=153
number>0,false
loop breaks..
so arm=num=153
so number 153 is an Armstrong number.
The output of the above program is given below:

Output:

c program