Advertisement
AdelinaMladenova

PascalTriangleMy

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