veronikaaa86

Triangle

Jan 31st, 2018
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1. namespace Ex03_PrintingTriangle
  2. {
  3.     using System;
  4.     public class Program
  5.     {
  6.         public static void Main()
  7.         {
  8.             int num = int.Parse(Console.ReadLine());
  9.             PrintTriangle(num);
  10.         }
  11.  
  12.         public static void PrintCol(int i)
  13.         {
  14.             for (int j = 1; j <= i; j++)
  15.             {
  16.                 Console.Write($"{j} ");
  17.             }
  18.             Console.WriteLine();
  19.         }
  20.  
  21.         public static void PrintTriangle(int n)
  22.         {
  23.             for (int i = 1; i <= n; i++)
  24.             {
  25.                 PrintCol(i);
  26.             }
  27.  
  28.             for (int i = n - 1; i >= 1; i--)
  29.             {
  30.                 PrintCol(i);
  31.             }
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment