三角形
图形一:
static void Main(string[] args)
{
int lines = 7;//7行
for (int i = 0; i < lines; i++)//打印的行数
{
for (int j = 0; j <= i; j++)//每行的个数
{
Console.Write("*");
}
Console.WriteLine();
}
图形二:
int lines = 7;
for (int i = 0; i < lines; i++)
{
for (int j = 0; j < lines - i; j++)
{
Console.Write("*");
}
Console.WriteLine();
}
图形三:
//可以看成一个“阴影”三角形和“*”三角形的组成的矩形
//先打印图形一,然后用阴影部分把“*”推进
int lines = 7;
for (int i = 0; i < lines; i++)
{
for (int k = 0; k < lines - i - 1; k++)
{
Console.Write(" ");
}
for (int j = 0; j <= i; j++)
{
Console.Write("*");
}
Console.WriteLine();
}
图形四:
//可以看成一个“阴影”三角形和“*”三角形的组成的矩形
//先打印图形二,然后用阴影部分把“*”推进
int lines = 7;
for (int i = 0; i < lines; i++)
{
for (int k = 0; k < i; k++)
{
Console.Write(" ");
}
for (int j = 0; j < lines - i; j++)
{
Console.Write("*");
}
Console.WriteLine();
}
图形五:
//先打印每行奇数个的三角形,再用阴影部分推进
int lines = 7;
for (int i = 0; i < lines; i++)
{
for (int k = 0; k < lines - i - 1; k++)
{
Console.Write(" ");
}
for (int j = 0; j < i * 2 + 1; j++)
{
Console.Write("*");
}
Console.WriteLine();
}
图形六:
int lines = 7;
for (int i = 0; i < lines; i++)
{
for (int k = 0; k < i; k++)
{
Console.Write(" ");
}
for (int j = 0; j < (lines - i) * 2 - 1; j++)
{
Console.Write("*");
}
Console.WriteLine();
}
图形七:
菱形:
//先打印上面的4层,再打印下面的3层,
for (int i = 0; i < 4; i++)
{
for (int k = 0; k < 4 - i - 1; k++)
{
Console.Write(” “);
}
for (int j = 0; j < i * 2 + 1; j++)
{
Console.Write(“*”);
}
Console.WriteLine();
}
for (int i = 0; i < 3; i++)
{
for (int k = 0; k <= i; k++)
{
Console.Write(” “);
}
for (int j = 0; j < (3 - i) * 2 - 1; j++)
{
Console.Write(“*”);
}
Console.WriteLine();
}
“`
九九乘法表:
for (int i = 1; i < 10; i++)
{
for (int j = 1; j <= i; j++)
{
Console.Write("{0}x{1}={2}\t", j, i, i * j);
}
Console.WriteLine();
}