C# 愛因斯坦走臺階:求滿足條件的最小臺階數是多少?
- 2021-11-01
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);
}
}
}
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;
}
}
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除了計算以外,什麼都不做。