题解 | #水仙花数#
水仙花数
https://www.nowcoder.com/practice/dc943274e8254a9eb074298fb2084703
#include <stdio.h> #include<math.h> int main() { int a, b, flag = 0; while (scanf("%d %d", &a, &b) != EOF) { // 注意 while 处理多个 case for (int i = a; i <= b; i++) { if ((pow(i % 10, 3) + pow(i / 10 % 10, 3) + pow(i / 100 % 10, 3)) == i) { printf("%d ", i); flag++; } } if (flag == 0) printf("no\n"); else printf("\n"); } return 0; }
C语言刷题 文章被收录于专栏
自己从头开始刷的C语言