saimun1

Methods. Debugging and Troubleshooting - Printing triangles

Sep 18th, 2017
96
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. //https://softuni.bg/trainings/resources/officedocument/11946/presentation-programming-fundamentals-january-2017
  3. namespace MethodsDemo
  4. {
  5.     public class Methods
  6.     {
  7.         public static void Main()
  8.         {
  9.  
  10.             int n = int.Parse(Console.ReadLine());
  11.             PrintTriangle(n);
  12.             Console.ReadLine();
  13.  
  14.         }
  15.  
  16.         public static void PrintColumns(int row)
  17.         {
  18.             for (int col = 1; col <= row; col++)
  19.             {
  20.                 Console.Write($"{col} ");
  21.             }
  22.             Console.WriteLine();
  23.  
  24.         }
  25.         public static void PrintTriangle(int n)
  26.         {
  27.             for (int row = 1; row <= n; row++)
  28.             {
  29.                 PrintColumns(row);
  30.             }
  31.  
  32.             for (int row = n - 1; row >= 1; row--)
  33.             {
  34.                 PrintColumns(row);
  35.             }
  36.         }
  37.  
  38.  
  39.  
  40.  
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment