Advertisement
skipter

C# Fundamentals - Triangle of Nums / Methods and loops

Jun 13th, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 KB | None | 0 0
  1. using System;
  2. namespace DataBytes___Lab
  3. {
  4.     class Program
  5.     {
  6.         static void Main(string[] args)
  7.         {
  8.             int n = int.Parse(Console.ReadLine());
  9.             PrintTriangle(n);
  10.         }  
  11.         static void PrintLineNumbers(int start, int end)
  12.         {
  13.             for (int i = start; i <= end; i++)
  14.             {
  15.                 Console.Write(i + " ");
  16.             }
  17.             Console.WriteLine();
  18.         }
  19.         static void PrintTriangle(int n)
  20.         {
  21.             for (int line = 1; line <= n; line++)
  22.             {
  23.                 PrintLineNumbers(1, line);
  24.             }
  25.             for (int line = n - 1; line >= 1; line--)
  26.             {
  27.                 PrintLineNumbers(1, line);
  28.             }
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement