kirililchev3

Printing Triangle - two methods two for loops

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