Advertisement
IvetValcheva

01. Number Pyramid

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