t_sh0w

01. Number Pyramid

Dec 15th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1. using System;
  2.  
  3. namespace NestedLoopsExercise1NumberPyramid
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int n = int.Parse(Console.ReadLine());
  10.  
  11.             int current = 1; // 2nd
  12.             bool isBigger = false; // 3rd
  13.  
  14.             for (int rows = 1; rows <= n; rows++)
  15.             {
  16.                 for (int cols = 1; cols <= rows; cols++)
  17.                 {
  18.                     if (current > n) // 4th
  19.                     {
  20.                         isBigger = true;
  21.                         break;
  22.                     }
  23.                     Console.Write($"{current} "); // 5th
  24.                     current++;
  25.                 }
  26.  
  27.                 if (isBigger) // 6th
  28.                 {
  29.                     break;
  30.                 }
  31.                 Console.WriteLine(); // 7th
  32.             }
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment