问题
输出所有的“水仙花数”。所谓“水仙花数”是指一个3位数,其各位数字立方和等于
该数本身。例如,153是一水仙花数。
#include <math.h>
#include <stdio.h>
int main() {
char str[4];
int n, a, b, c;
gets(str);
sscanf(str, "%d", &n);
sscanf(str, "%1d%1d%1d", &a, &b, &c);
if (pow(a, 3) + pow(b, 3) + pow(c, 3) == n) {
printf("yes");
} else {
printf("no");
}
}
博客聚焦于用C和C++语言解决输出所有“水仙花数”的问题。“水仙花数”是指各位数字立方和等于该数本身的3位数,如153。通过代码实现找出并输出这些数,体现了C和C++在算法实现上的应用。
96

被折叠的 条评论
为什么被折叠?



