Q:

write a C program to check whether a number is Armstrong or not Armstrong

0

write a C program to check whether a number is Armstrong or not Armstrong.

-----------------------------------------------------------------------------------

A number is called Armstrong number if it is equal to the sum of the cubes of its own digits.

For example: 153 is an Armstrong number since 153 = 1*1*1 + 5*5*5 + 3*3*3.

The Armstrong number is also known as narcissistic number.

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

int number;
printf("enter the number:");
scanf("%d",&number);
int sum=0;
int temp=number;
int digit;
while(temp>0)
{
    digit=temp%10;
    sum+=digit*digit*digit;  //same as sum=sum+digit*digit*digit
    temp=(int)(temp/10);
}
if(number==sum)
printf("%d is an armstrong number",number);
else
printf("%d is Not an armstrong number",number);


    return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now