Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace SoftUniNetCore
- {
- class Program
- {
- static void Main(string[] args)
- {
- /*
- The triangle may be constructed in the following manner: In row 0 (the topmost row),
- there is a unique nonzero entry 1. Each entry of each subsequent row is constructed by
- adding the number above and to the left with the number above and to the right, treating blank
- entries as 0. For example, the initial number in the first (or any other) row is 1 (the sum of 0 and 1),
- whereas the numbers 1 and 3 in the third row are added to produce the number 4 in the fourth row.
- */
- int countOfRows = int.Parse(Console.ReadLine());
- long[][] pascalTriangle = new long[countOfRows][];
- pascalTriangle[0] = new long[1];
- pascalTriangle[0][0] = 1;
- for (int i = 1; i < countOfRows; i++)
- {
- pascalTriangle[i] = new long[i + 1];
- pascalTriangle[i][0] = 1;
- pascalTriangle[i][pascalTriangle[i].Length-1] = 1;
- for (int a = 1; a < pascalTriangle[i].Length-1; a++)
- {
- pascalTriangle[i][a] = (pascalTriangle[i - 1][a - 1] + pascalTriangle[i - 1][a]);
- }
- }
- for (int i = 0; i < pascalTriangle.Length; i++)
- {
- for (int a = 0; a < pascalTriangle[i].Length; a++)
- {
- Console.Write(pascalTriangle[i][a] + " ");
- }
- Console.WriteLine();
- }
- }
- }
- }
RAW Paste Data



