改正求水仙花数的这段代码#include<stdio.h> int is(int number); int main(void) { int number, m, n; scanf("%d,%d", &m, &n); for (number = m; number <= n; number++) printf("%d\n", is(number)); return 0; } int is(int number) {int x, y, z; x = number % 10; y = number / 10 % 10; z = number / 100; if (x*x*x + y*y*y + z*z*z == number) {result = number; return result;} }
时间: 2024-03-02 12:48:35 浏览: 46
水仙花数的代码
在代码中,函数is没有返回值,应该将int改为void,并将if语句中的return语句改为printf语句输出水仙花数。修改后的代码如下:
```
#include <stdio.h>
void is(int number);
int main(void) {
int number, m, n;
scanf("%d,%d", &m, &n);
for (number = m; number <= n; number++) {
is(number);
}
return 0;
}
void is(int number) {
int x, y, z;
x = number % 10;
y = number / 10 % 10;
z = number / 100;
if (x*x*x + y*y*y + z*z*z == number) {
printf("%d\n", number);
}
}
```
阅读全文