#include <stdio.h>
int main()
{
int a,b,c,d,e,f,g;
int x = 0;
int y = 1;
while(scanf("%d %d",&a,&b) != EOF){
for (c = a,x = 0;c<=b;c++){
e = c%10;
f = (c/10)%10;
g = (c/100)%10;
//printf("%d/n",g);
if (e*e*e+f*f*f+g*g*g == c){
printf("%d ",c);
x++;
}
}
printf("%c",8);
if(x == 0){
printf("no");
}
printf("\n");
}
return 0;
}
供参考:
#include <stdio.h>
int main()
{
int a, b, c, d, e, f, g;
int x = 0;
//int y = 1;
while (scanf("%d %d", &a, &b) == 2 && a != 0 && b != 0) {//输入0 0 结束输入,或输入非数字结束输入
if (a < 100 || b >= 1000) continue;
for (c = a, x = 0; c <= b; c++) {
e = c % 10;
f = (c / 10) % 10;
g = (c / 100) % 10;
//printf("%d/n",g);
if (e * e * e + f * f * f + g * g * g == c) {
printf("%d ", c);
x++;
}
}
//printf("%c", 8);
if (x == 0) {
printf("no\n");
}else
printf("\n");
}
return 0;
}
你输出no时也要换行,你弄个测试样例,输出一遍不难看出的。