An Armstrong number is defined as the sum
of power of each digit to a n digit number is equal to that number.
3-digit: 153, 370, 371, 407
4-digit: 1634, 8208, 9474
Example 1 (3-digit number):
Number: 153
Digits: 1,5,3
Number of digits: 3
Calculation: 13+53+33
1+125+27 = 153
Example 2 (4-digit number):
1Number: 1634
Digits: 1,6,3,4
Number of digits: 4
Calculation: 14+64+34+44
1+1296+81+256 =1634
#include<stdio.h>
main()
{
int n,r,x,sum=0;
printf("\nEnter Number : ");
scanf("%d",&n);
x=n;
while(n!=0)
{
r=n%10;
sum+=r*r*r;
n/=10;
}
printf("\n%d Sum of Cube = %d",x,sum);
if(x==sum)
printf("\nThe Given %d no is Armstrong Number",x);
else
printf("\nThe Given %d no is Not Armstrong Number",x);
}
Output