Armstrong numbers

Logic behind it...

sum of the cubes of individual digit of the number should be equal to the same number.


{int n,m,s;

...

scanf("%d",&n);

m=n;

s=0;

while(n>0)

{

s=s+((n%10)*(n%10)*(n%10));// s=s+pow((n%10),3);

n=n/10;

}

if (m==s)

printf("Armstrong Number!");

else

printf("Not an armstrong !");

}

No comments: