C#打印直角三角形、等腰三角形、九九乘法表

使用for循环打印直角三角形

 for (int i = 1; i <= 9; i++)
            {
                Console.WriteLine();
                for (int j = 1; j <= i; j++)
                {
                    Console.Write( "*" );
                    Console.Write(" ");
                }
            }
 Console.Read();

使用for循环打印等腰三角形

for (int i = 1; i <= 9; i++)
            {
                Console.WriteLine();
                for (int j = 1; j <= 9-i; j++)
                {
                    Console.Write(" ");
                }
                for (int j = 1; j < 2 *  i- 1; j++)
                {
                    if (i==9 || j==1 || j==2*i-1)
                    {
                        Console.Write(" ");
                    }
                    else
                    {
                        Console.Write("*");
                    }
                }
            }
            Console.Read();

打印九九乘法表

for (int i = 1; i <= 9; i++)
            {
                Console.WriteLine();
                for (int j = 1; j <= i; j++)
                {
                    Console.Write(j + "*" + i + "=" + j * i);
                    Console.Write(" ");
                }
            }
Console.Read();

 

©️2020 CSDN 皮肤主题: 书香水墨 设计师:CSDN官方博客 返回首页