C# 愛因斯坦走臺階:求滿足條件的最小臺階數是多少?

  • 作者:由 匿名使用者 發表于 書法
  • 2021-11-01

C# 愛因斯坦走臺階:求滿足條件的最小臺階數是多少? 匿名使用者 1級 2019-01-08 回答

using System;

namespace welcome

{

class Class1

{

static void Main(string[] args)

{

int x;

for(x=7;x<200;x++)

if(x%2==1 && x%3==2 && x%4==3 && x%5==4 && x%6==5 && x%7==0)

Console。WriteLine(“{0}”,x);

}

}

}

C# 愛因斯坦走臺階:求滿足條件的最小臺階數是多少? 匿名使用者 1級 2019-01-08 回答

for(x=7;x<200;x+=7)

{

if(x%2==1 && x%3==2 && x%4==3 && x%5==4 && x%6==5 && x%7==0)

{

Console。WriteLine(“{0}”,x);

break;

}

}

C# 愛因斯坦走臺階:求滿足條件的最小臺階數是多少? 恩賜解脫 1級 2019-01-08 回答

using System;

namespace welcome {

class Class1 {

static void Main(string[] args) {

int x;

for(x = 7; x < 200; x += 7) {

x % 2 == 1 &&

x % 3 == 2 &&

x % 4 == 3 &&

x % 5 == 4 &&

x % 6 == 5 &&

x % 7 == 0;

}

Console。WriteLine(“{0}”, x);

}

}

}

錯誤之處,x+7,這裡應該是個控制因子的遞增,而x+7除了計算以外,什麼都不做。

Top