/*Program to check whether the number is armstrong or not.*/
#include <stdio.h>
int main()
{
int sum=0,num,temp,i;
printf("Enter the number to check:");
scanf("%d",&num);
temp=num;
while(num>0)
{
i=num%10;
sum+=i*i*i;
num=num/10;
}
if (sum==temp)
printf("%d is an armstrong number as its cube sum equals to %d",temp,sum);
else
printf("%d is not an armstrong number",temp);
return 0;
}
OUTPUT:
DESCRIPTION:
In this variable we ask the user to input a number and we take out the each digit of number and cube it and is stored in a variable. In this way,we finally compare the value of num and sum then we display the result.
USED VARIABLE:
1.sum=it is used to store the value of the sum of cube of each digit.
2.i=it is used to store the last digit of the number.
3.temp=it is used to store the value for future need.
4.num=used to store the user input value.

Sir, I really appreciate you. Your every program is awesome and clear and helpful.
ReplyDelete