Armstrong number:
-A number which is equal to the sum of the power of digit by its length is called as Armstrong number.
Example-
1,2,3,4,5,6,7,8,9
these all are Armstrong number
370,371 are Armstrong number.
How ?
370=3^3+7^3+0^3
-Here '^' shows the power function.
-Here we print the all possible Armstrong number betweeen the 0 and 1000
program:
#include < iostream>
#include< math.h>
using namespace std;
class r4r
{
public:
int Armstrong(int n)
{
int length=0,sum=0,n1;
n1=n;
while(n)
{
length++;
n=n/10;
}
n=n1;
while(n)
{
sum=sum+pow(n%10,length);
n=n/10;
}
if(sum==n1)
cout<< n1<<",";
}
};
int main()
{
int n;
r4r obj;
for(n=1;n< 1000;n++)
obj.Armstrong(n);
return 0;
}
0,1,2,3,4,5,6,7,8,9,153,370,371,407