THOSE NUMBERS WHOSE SUM OF ITS DIGITS TO POWER OF NUMBER OF ITS DIGITS IS EQUAL TO THAT NUMBER ARE KNOWN AS ARMSTRONG NUMBER
FOR EXAMPLE: 153
TOTAL DIGITS IN 153 IS 3
THEREFORE = 1^3 + 5^3 +3^3
= 1 + 125 + 27
= 153
FOR EXAMPLE: 1634
TOTAL DIGITS IN 1634 IS 4
THEREFORE = 1^4 + 6^4 + 3^4 + 4^4
= 1 + 1296 + 81 + 64
= 1634
// prg to illustrate given number is Armstrong or not
scanf("%d",&n);
temp=n;
while(n != 0)
{
r = n % 10;
n = n / 10;
arm=arm + (r * r * r);
}
if( temp == arm )
printf("%d is an armstrong \n",temp);
else
printf("%d is not a armstrong \n",temp);
}
OUTPUT:
#include<stdio.h>
void main()
{
printf("enter any number:");
int n,r,arm=0,temp;
scanf("%d",&n);
temp=n;
while(n != 0)
{
r = n % 10;
n = n / 10;
arm=arm + (r * r * r);
}
if( temp == arm )
printf("%d is an armstrong \n",temp);
else
printf("%d is not a armstrong \n",temp);
}
OUTPUT:
No comments:
Post a Comment