为什么我求不出水仙花数..

img

img


答案不对呀,也不知道是哪里出问题了,是新shou,解答请详细一点idhcnxjdjennfjjxhaneudbnxksisjdbxoivoapwndbnf

if判断时,=是赋值不是判断,改为==
while 后面的代码,应该在do while 循环里面的,不是在后面。

img

#include<iostream>
using namespace std;
int main() {
  int num = 100;
  do{
      int a, b, c;
      a = num % 10;
      b = num / 10 % 10;
      c = num / 100;
      if (num==a * a * a + b * b * b + c * c * c) {
          cout << num << endl;
      }
      num++;
  } while (num < 1000);
  return 0;
}

你这都没写到循环里边去,修改如下

int main() {
  int num = 100;
  do{
      int a, b, c;
      a = num % 10;
      b = num / 10 % 10;
      c = num / 100;
      if (a * a * a + b * b * b + c * c * c == num) {
          cout << num << endl;
      }
      num++;
  } while (num < 1000);
}

img

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632