循环语句练习(1)
1.一个小球从100米空中落下,每次反弹一半高度,请问第10次反弹的高度是多少?小球总共经过多少米?
点击查看代码
double height = 100, sum=100, jump=0;
for (int i = 1;i<=10;i++)
{
jump=height/=2;
sum+=height*2;
}
Console.WriteLine($"第十次弹跳的高度:{jump}米");
Console.WriteLine($"第十次经过了{sum - jump}米");
点击查看代码
for (int i = 1; i < 10; i++)
{
for (int j = 1; j < i+1; j++)
{
Console.Write(j + "*" + i + "=" + j * i + "\t");
}
Console.WriteLine();
}
点击查看代码
int sum = 0;
Console.WriteLine("组合的三位数:");
for (int i = 1; i < 5; i++)
{
for (int j = 1; j < 5; j++)
{
for (int k = 1; k < 5; k++)
{
if (i != j && j != k && k != j)
{
Console.Write(i * 100 + j * 10 + k + "\t");
sum++;
}
}
}
}
Console.WriteLine();
Console.WriteLine($"可以组成{sum}个");
点击查看代码
int sum = 0;
Console.WriteLine("101-200之间的素数有:");
for (int i = 101; i <= 200; i++)
{
int j = 2;
for (; j < i; j++)
{
if (i % j == 0)
{
break;
}
}
if (j == i)
{
Console.Write(i + "\t");
sum++;
}
}
Console.WriteLine();
Console.WriteLine($"一共有{sum}个素数");