Advertisement
VelizarAvramov

03. Printing Triangle

Nov 17th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _03._Printing_Triangle
  4. {
  5.     class PrintTriangle
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int n = int.Parse(Console.ReadLine());
  10.             PrintTrianglee(n);
  11.  
  12.         }
  13.  
  14.         private static void PrintTrianglee(int n)
  15.         {
  16.             PrintTopPart(n);
  17.             PrintBottomPart(n);
  18.         }
  19.  
  20.         private static void PrintBottomPart(int n)
  21.         {
  22.             for (int i = n - 1; i >= 1; i--)
  23.             {
  24.                 for (int j = 1; j <= i; j++)
  25.                 {
  26.                     Console.Write($"{j} ");
  27.                 }
  28.                 Console.WriteLine();
  29.             }
  30.         }
  31.  
  32.         private static void PrintTopPart(int n)
  33.         {
  34.             for (int i = 1; i <= n; i++)
  35.             {
  36.                 for (int j = 1; j <= i; j++)
  37.                 {
  38.                     Console.Write($"{j} ");
  39.                 }
  40.                 Console.WriteLine();
  41.             }
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement