simonakancheva

02. Number Pyramid

Apr 21st, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 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 ConsoleApp65
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.             int current = 1;
  15.             bool isBigger = false;
  16.             for (int rows = 1; rows <= n; rows++)
  17.             {
  18.                 for (int cols = 1; cols <= rows; cols++)
  19.                 {
  20.                     if (current>n)
  21.                     {
  22.                         isBigger = true;
  23.                         break;
  24.                     }
  25.                     Console.WriteLine(current + " ");
  26.                     current++;
  27.                 }
  28.                 if (isBigger)
  29.                 {
  30.                     break;
  31.                 }
  32.                 Console.WriteLine();
  33.             }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment