如果一个正整数等于其各个数字的立方和,则该数称为阿姆斯特朗数(亦称为自恋性数)。如407=4^3+0^3+7^3就是一个阿姆斯特朗数。试编程求1000内的所有3位数的阿姆斯特朗数。
**输出格式要求:"There are following Armstrong number smaller than 1000:\n" " %d "
程序运行示例如下:
There are following Armstrong number smaller than 1000:
153 370 371 407
#include<stdio.h>
int main()
{
printf("There are following Armstrong number smaller than 1000:\n");
int i, j, h;
int b, c, d;
int a[4];
for (i = 100; i < 1000; i++)
{
b = i % 10;
c = i / 100;
d = (i % 100) / 10;
if (i == d * d * d + b * b * b + c * c * c)
printf(" %d ", i);
}
return 0;
}