#include"stdio.h"
main()
{
int m,n,a,x,y,z,d=0;
while(scanf("%d%d",&m,&n)!=EOF)
if(m >= 100 && m <= n && n<=999)
{
for(a=m;a<n;a++)
x=a/100;
y=a/10%10;
z=a%10;
if(a == x * x * x + y * y * y + z * z * z )
printf("%d",a);
d++;
}
if(d==0)
printf("no");
}
C程序求两数间的水仙花数问题。求正确答案。。说出怎么改。。谢谢!
答案:3 悬赏:0 手机版
解决时间 2021-03-09 00:56
- 提问者网友:骑士
- 2021-03-08 13:18
最佳答案
- 五星知识达人网友:大漠
- 2021-03-08 13:55
已改,楼主要运用好括号啊
#include <stdio.h>
void main()
{
int m,n,a,x,y,z,d=0;
while(scanf("%d%d",&m,&n)!=EOF)
{
d = 0; //把d每次都先赋值0
if(m >= 100 && m <= n && n<=999)
{
for (a = m; a <= n; a++) //for要括号括住多个语句
{
x=a/100;
y=a/10%10;
z=a%10;
if(a == x * x * x + y * y * y + z * z * z )
printf("%d ",a);
d++;
}
}
if(d==0)
printf("no");
printf("\n");
}
}
#include <stdio.h>
void main()
{
int m,n,a,x,y,z,d=0;
while(scanf("%d%d",&m,&n)!=EOF)
{
d = 0; //把d每次都先赋值0
if(m >= 100 && m <= n && n<=999)
{
for (a = m; a <= n; a++) //for要括号括住多个语句
{
x=a/100;
y=a/10%10;
z=a%10;
if(a == x * x * x + y * y * y + z * z * z )
printf("%d ",a);
d++;
}
}
if(d==0)
printf("no");
printf("\n");
}
}
全部回答
- 1楼网友:枭雄戏美人
- 2021-03-08 15:15
#include"stdio.h"
main()
{
int m,n,a,x,y,z,d=0;
scanf("%d%d",&m,&n);
if(m >= 100 && m <= n && n<=999)
{
for(a=m;a<n;a++)
{
x=a/100;
y=a/10%10;
z=a%10;
if(a == x * x * x + y * y * y + z * z * z )
printf("%d",a);
d++;
}
}
if(d==0)
printf("no");
}
你思路是对的... 自己把自己写乱了...去了点东西就好了
- 2楼网友:动情书生
- 2021-03-08 14:29
#include <iostream>
#include <cstdlib>
using namespace std;
inline int cube ( const int n ){ return n * n * n;}
bool isnarcissistic ( const int n ){
int hundreds = n / 100;
int tens = n / 10 - hundreds * 10;
int ones = n % 10;
return cube(hundreds) + cube(tens) + cube(ones) == n;
}
int main(){
int sum = 0 ;
for ( int i = 1; i < 10000; ++ i ){
if ( isnarcissistic(i) )
{
cout << i <<" " ;
sum += i ;
}
}
cout << "\nsum = " << sum << endl ;
return exit_success;
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯