IvetValcheva

01. Number Pyramid

Dec 4th, 2021
182
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.  
  3. namespace ConsoleApp17
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int n = int.Parse(Console.ReadLine());
  10.  
  11.             int current = 1;
  12.  
  13.             for (int rows = 1; rows <= n; rows++)
  14.             {
  15.                 for (int cols =1; cols <= rows; cols++)
  16.                 {
  17.                     if (current > n)
  18.                     {
  19.                         break;
  20.                     }
  21.                     Console.Write(current + " ");
  22.                     current++;
  23.                 }
  24.                 if (current > n)
  25.                 {
  26.                     break;
  27.                 }
  28.                 Console.WriteLine();
  29.             }
  30.         }
  31.     }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment