anizko

2. Pascal Triangle

Jun 4th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _02._Pascal_Triangle
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int numberRows = int.Parse(Console.ReadLine());
  11.  
  12.             int[] priviusRows = new int[0];
  13.  
  14.             for (int i = 0; i < numberRows; i++)
  15.             {
  16.                 int[] row = new int[i+1];
  17.                 row[0] = 1;
  18.                 if (i == 0 || i == 1)
  19.                 {
  20.                     row[i] = 1;
  21.  
  22.                 }
  23.  
  24.                 else
  25.                 {
  26.  
  27.                     for (int j = 1; j < i; j++)
  28.                     {
  29.                         row[i] = priviusRows[j];
  30.                         row[j] = priviusRows[j] + priviusRows[j - 1];
  31.  
  32.                     }
  33.  
  34.                 }
  35.                
  36.                 Console.Write(string.Join(" ",row));
  37.                    
  38.                 Console.WriteLine();
  39.  
  40.                 priviusRows = row;
  41.  
  42.             }
  43.  
  44.  
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment