BubaLazi

Printing Triangle

Jul 7th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 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 ConsoleApp1
  8. {
  9.     class Program
  10.     {
  11.  
  12.  
  13.         static void Main(string[] args)
  14.         {
  15.             int n = int.Parse(Console.ReadLine());
  16.            
  17.  
  18.             for( int i = 0; i < n; i++)
  19.             {
  20.                 PrintLine(1, i);
  21.             }
  22.  
  23.             PrintLine(1, n);
  24.  
  25.             for(int i = n-1; i >= 0; i --)
  26.             {
  27.                 PrintLine(1, i);
  28.             }
  29.         }
  30.  
  31.         static void PrintLine(int start,int end)
  32.         {
  33.  
  34.            
  35.             for(int i = start; i <= end; i++)
  36.             {
  37.                 Console.Write(i + " ");
  38.             }
  39.             Console.WriteLine();
  40.  
  41.  
  42.         }
  43.        
  44.  
  45.    
  46.        
  47.  
  48.        
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment