Advertisement
Dianov

Nested Loops - Exercise (01. Number Pyramid)

Mar 4th, 2021
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace NumberPyramid
  8.  
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             int n = int.Parse(Console.ReadLine());
  15.             int num = 1;
  16.  
  17.             for (int row = 1; row <= n; row++)
  18.             {
  19.                 for (int col = 1; col <= row; col++)
  20.                 {
  21.                     Console.Write($"{num} ");
  22.                     num++;
  23.                     if (num > n)
  24.                     {
  25.                         Environment.Exit(0);
  26.                     }
  27.                 }
  28.                 Console.WriteLine();
  29.             }
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement