求100到1000之间的水仙花数
“水仙花数(Narcissistic number)也被称为超完全数字不变数(pluperfect digital invariant, PPDI)、自恋数、自幂数、阿姆斯壮数或阿姆斯特朗数(Armstrong number),水仙花数是指一个 3 位数,它的每个位上的数字的 3次幂之和等于它本身。例如:1^3 + 5^3+ 3^3 = 153。基本信息定义水仙花数只是自幂数的一种,严格来说3位数的3次幂数才称为水仙花数。
#include "math.h"
#include "stdio.h"
int main() {
int a, b, c;
for (int i = 100; i < 1000; i++) {
//百位数
a = i / 100;
//十位数
b = i / 10 % 10;
//个位
c = i % 100 % 10;
//printf("%d\t", a);
//printf("%d\t", b);
//printf("%d\t", c);
if (pow(a, 3) + pow(b, 3) + pow(c, 3) == i) {
printf("%d\t", i);
}
}
}