koksibg

Printing_Triangle

Jan 23rd, 2017
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Printing_Triangle
  8. {
  9.     class Printing_Triangle
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.             PrintTriangle(n);
  15.  
  16.  
  17.         }
  18.  
  19.         static void PrintLine(int start, int end)
  20.         {
  21.             for (int i = start; i <= end; i++)
  22.             {
  23.                 Console.Write(i + " ");
  24.             }
  25.             Console.WriteLine();
  26.         }
  27.  
  28.         static void PrintTriangle(int n)
  29.         {
  30.             for (int line = 1; line <= n; line++)
  31.             {
  32.                 PrintLine(1, line);
  33.             }
  34.  
  35.             for (int line = n - 1; line >= 1; line--)
  36.             {
  37.                 PrintLine(1, line);
  38.             }
  39.         }
  40.  
  41.     }
  42. }
Add Comment
Please, Sign In to add comment