05-08 水仙花数

作者: freeWings2017分类: 校园学习 发布时间: 2023-11-21 20:31:45 浏览:264 次

05-08 水仙花数

freeWings2017:
【参考代码】 #include<stdio.h> #include<math.h> int main() { int n,a,b,c,s; printf("水仙花数有:"); for(n=100;n<=999;n++) { a=n/100; b=n/10%10; c=n%10; //s=a*a*a+b*b*b+c*c*c; s=pow(a,3)+pow(b,3)+pow(c,3); if(s==n) printf("%d,",n); } printf("\b."); return 0; } 【运行结果】 水仙花数有:153,370,371,407. --------------------------------

习题 第五版 C程序设计 谭浩强

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!