for循环语句之棋盘放粮食、百鸡百钱、纸张的折叠问题

时间:2021-11-13 00:53:14

1.棋盘放粮食

            int lszl = ;

            for (int i = ; i < ; i++)
{
int x = ;
for (int j = ; j <= i; j++)
{
x = x * ;
}
lszl = lszl + x;
}
double zl = lszl * 0.001;
Console.WriteLine("放满整个棋盘所需要:" + zl + "kg的粮食");

2.百鸡百钱

 for (int i = ; i < ; i++)
{
for (int j = ; j < ; j++)
{
for (int k = ; k < ; k++)
{
double a = i*+j*+k*0.5;
if (a == )
{
Console.WriteLine("买大鸡:"+i+"只,小鸡"+j+"只,幼鸡"+k+"只");
}
}
}
}

3.一张纸厚度是0.1毫米,假设这张纸可以限次对折,问对折几次可以超过珠峰?8848米

 int a = ;
double z = 0.0001; for (int i = ; i <= i+; i++)
{
z = z * ;
if (z > )
{
a = i;
break;
}
}
Console.WriteLine("折" + a + "次可以跟珠穆朗玛峰一样高");