|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #include<stdio.h>
- #include<math.h>
- int main(){
- int a, b, c, d, e, t, num;
- int cnt = 0;
- while (scanf("%d %d", &a, &b) != EOF){
- for (num = a; num <= b; ++num){
- t = num;
- c = t % 10;
- t /= 10;
- d = t % 10;
- t /= 10;
- e = t % 10;
- if (num == c*c*c+ d*d*d + e*e*e){
- cnt++;
- if (cnt == 1)
- printf("%d", num);
- else if (cnt > 1)
- printf(" %d", num);
- }
- }
- if (cnt==0)
- printf("no\n");
- else
- printf("\n");
- }
-
- return 0;
- }
-
复制代码
从你的程序第16行来看,你的目的应该是输出水仙花数我没时间了,要去上班了,给你一个输出水仙花数的程序作参考吧:
- #include <stdio.h>
- int main()
- {
- int bai, shi, ge, n;
- printf("result is: ");
- for(n = 100;n < 1000;n++ ) /*整数的取值范围*/
- {
- bai = n / 100;
- shi = (n - bai * 100) / 10;
- ge = n % 10;
- if(n == bai * bai * bai + shi * shi * shi + ge * ge * ge) /*各位上的立方和是否与原数n相等*/
- printf("%d ", n);
- }
- printf("\n");
-
- return 0;
- }
复制代码
|
|