Sybatron

2.Pascal Triangle

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