csharp 使用嵌套for循环打印数字三角形。从C#http://www.introprogramming.info/wp-cont的计算机编程基础知识

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 使用嵌套for循环打印数字三角形。从C#http://www.introprogramming.info/wp-cont的计算机编程基础知识相关的知识,希望对你有一定的参考价值。

int n = int.Parse(Console.ReadLine());

for (int row = 1; row <= n; row++)
{
  for (int col = 1; col <= row; col++)
  {
    Console.Write(col + " ");
  }
  Console.WriteLine();
}

// 8

// 1
// 1 2
// 1 2 3
// 1 2 3 4
// 1 2 3 4 5
// 1 2 3 4 5 6
// 1 2 3 4 5 6 7
// 1 2 3 4 5 6 7 8

以上是关于csharp 使用嵌套for循环打印数字三角形。从C#http://www.introprogramming.info/wp-cont的计算机编程基础知识的主要内容,如果未能解决你的问题,请参考以下文章