Advertisement
VanessaShopping

03. Printing Triangle

Jan 23rd, 2017
918
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 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 _03.Printing_Triangle
  8. {
  9.     class PrintingTriangle
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.  
  15.             for (int i = 1; i <= n; i++)
  16.                 PrintLine(1, i); // Print 1... 1 2 ... 1 2 3 .... 1 2 3 n
  17.  
  18.             //for (int j = n - 1; j >= 1; j--)
  19.             //    PrintLine(1, j); // Print 1 2 3 n ... 1 2 ... 1
  20.             for (int j = 1; j <= n - 1; j++)
  21.                 PrintLine(1, n - j);
  22.         }
  23.         private static void PrintLine(int start, int end)
  24.         {
  25.             for (int i = start; i <= end; i++)
  26.             {
  27.                 Console.Write(i + " ");
  28.             }
  29.             Console.WriteLine();
  30.         }
  31.  
  32.         //    TopTriangle(n);
  33.         //    BottomTriangle(n);
  34.         //}
  35.  
  36.         //private static void BottomTriangle(int n)
  37.         //{
  38.         //    for (int i = n-1; i > 0 ; i--)
  39.         //    {
  40.         //        for (int j = 1; j <= i; j++)
  41.         //        {
  42.         //            Console.Write(j + " ");
  43.         //        }
  44.         //        Console.WriteLine();
  45.         //    }
  46.         //}
  47.  
  48.         //private static void TopTriangle(int n)
  49.         //{
  50.         //    for (int i = 1; i <= n; i++)
  51.         //    {
  52.         //        for (int a = 1; a <= i; a++)
  53.         //        {
  54.         //            Console.Write(a + " ");
  55.         //        }
  56.         //        Console.WriteLine();
  57.         //    }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement