Facebook Google Plus YouTube

Check Armstrong number in a range 1 to 250.

Armstrong Number:
A number is refer as Armstrong number if the numbers each digits cubic sum is equivalent to that number.
Example: 153 = (1)^3 + (5)^3 + (3)^3.

#include <stdio.h>
int main()
{
int number,i,j,sum,reminder,tempo,min=1,max=250;
//printf("Enter a number\n");
//scanf("%d",&number);
for(number=min;number<=max;number++)
{

tempo =number;
sum=0;

while(tempo != 0)
{
reminder = tempo%10;
sum=sum+(reminder*reminder*reminder);
tempo=tempo/10;
}
if(sum==number)
{
printf("%d is a armstrong number\n",number);
}
}
return 0;
}

Output:

1 is a armstrong number.

153 is a armstrong number.

Leave a Reply

%d bloggers like this: