jloga4
1/2/2017 - 11:41 PM

Print triangle of numbers using nested for loops. From Fundamentals of Computer Programming with C# http://www.introprogramming.info/wp-cont

Print triangle of numbers using nested for loops. From Fundamentals of Computer Programming with C# http://www.introprogramming.info/wp-content/uploads/2013/07/Books/CSharpEn/Fundamentals-of-Computer-Programming-with-CSharp-Nakov-eBook-v2013.pdf

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