当前位置: 代码迷 >> 综合 >> C#打印直角三角形、等腰三角形、九九乘法表
  详细解决方案

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

热度:53   发布时间:2024-01-30 08:26:47.0

使用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();

 

  相关解决方案