//打印100到999的水仙花数,各个位数字的三次方之和等于这些数字组合的数字
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(){
int s, a, b, c;
for (s = 100; s <= 999; s++)
{
a = s / 100;
b = (s / 10) % 10;//也可以写成b=(s%100)/10
c = s % 10;
if (s == pow(a, 3) + pow(b, 3) + pow(c, 3))
printf("%d\n", s);
}
system(“pause”);
return 0;
}
打印100到999的水仙花数(c语言)
最新推荐文章于 2023-11-27 21:31:56 发布