1.十八个年龄
Console.Write("请输入您的名字:");
string a = Console.ReadLine();
for (int i = 1; i <= 18;i++ )
{
Console.Write("我叫"+a+","+"我今年"+i+"岁了。");
switch (i)
{
case 6: Console.Write("我上小学了!"); break;
case 11: Console.Write("我上初中了!"); break;
case 15: Console.Write("我上高中了!"); break;
case 18: Console.Write("我成年了!考上了北大!"); break;
}
Console.WriteLine();
}
Console.ReadLine();
2.99乘法表
for (int i = 1; i <= 9; i++)
{
for (int l = 1; l <= i; l++)
{
int a = l * i;
Console.Write(l + "*" + i + "=" + a + " ");
}
Console.WriteLine();
}
3.各种三角形
//三角形1
for (int i = 1; i <= 5; i++)
{
for (int l = 1; l <= i; l++)
{
Console.Write("★");
}
Console.WriteLine();
}
//三角形2
for (int i = 1; i <= 5; i++)
{
for (int l = i; l <= 5; l++)
{
Console.Write("★");
}
Console.WriteLine();
}
//三角形3
for (int i = 1; i <= 5; i++)
{
for (int l = i; l < 5; l++)
{
Console.Write(" ");
}
for (int l = 1; l <= i; l++)
{
Console.Write("★");
}
Console.WriteLine();
}
//三角形4
for (int i = 1; i <= 5; i++)
{
for (int l = 1; l < i; l++)
{
Console.Write(" ");
}
for (int l = i; l <= 5; l++)
{
Console.Write("★");
}
Console.WriteLine();
}
//三角形5
for (int i = 1; i <= 5; i++)
{
for (int l = i; l < 5; l++)
{
Console.Write(" ");
}
for (int l = 1; l <= i; l++)
{
Console.Write("★");
}
Console.WriteLine();
}
4.菱形
Console.Write("请输入一个数字");
int a = int.Parse(Console.ReadLine());
for (int i = 1; i <= a; i++)
{
for (int l = i; l < a; l++)
{
Console.Write(" ");
}
for (int l = 1; l <= i; l++)
{
Console.Write("★");
}
Console.WriteLine();
}
for (int i = 1; i <= a; i++)
{
for (int l = 0; l < i; l++)
{
Console.Write(" ");
}
for (int l = i; l <= (a - 1); l++)
{
Console.Write("★");
}
Console.WriteLine();
}