语句
顺序语句
分支语句
循环语句
1、初始条件
2、循环条件
3、循环体
4、状态改变
for(初始条件;循环条件;状态改变)
{
循环体;
}
穷举法
迭代法
1、
Console.Write("请输入个数:");
int n = Convert.ToInt32(Console.ReadLine());
for (int i = 1; i <= n; i++)
{
for (int a = 1; a <= n - i; a++)
{
Console.Write(" ");
}
for (int b = 1; b <= (2 * i - 1); b++)
{
Console.Write("☆");
}
Console.Write("\n");
}
for (int j = 1; j < n ; j++)
{
for (int c = 1; c <= j; c++)
{
Console.Write(" ");
}
for (int d = 1; d <= 2*(n - j) - 1; d++)
{
Console.Write("☆");
}
Console.Write("\n");
}
2、一篮球从10米高落下,每次弹起高度是上次高度的3/4,输入次数,求弹起高度
Console.Write("请输入次数:");
int n = Convert.ToInt32(Console.ReadLine());
double h = 10;
for (int i = 1; i <= n; i++)
{
h*=3/4;
Console.WriteLine("弹起高度" + h);
}
3、一对幼兔一个月后长成小兔(每对兔子默认一公一母),再过一个月长成成兔并且生下一对小兔,以此类推,两年后有多少对兔子?
int a = 1, b = 0, c = 0, m = 0, n = 0;
for (int i = 1; i <= 24; i++)
{
if (i == 1)
{
m = 1;
n = 0;
c = 0;
}
else
{
m = b + c;
n = a;
c = m;
a = m;
b = n;
}
Console.WriteLine(i);
Console.WriteLine("幼兔:" + m);
Console.WriteLine("小兔:" + n);
Console.WriteLine("大兔:" + c);
Console.WriteLine("总数:" + (m + n + c));
}
原文:http://www.cnblogs.com/phantom-k/p/3922252.html