Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _4.Pascal_Triangle
- {
- public class Program
- {
- public static void Main()
- {
- var n = long.Parse(Console.ReadLine());
- if (n == 1)
- {
- Console.WriteLine(1);
- }
- else
- {
- var pascalTringleMatrix = new long[n][];
- pascalTringleMatrix[0] = new long[] { 1 };
- pascalTringleMatrix[1] = new long[] { 1, 1 };
- for (int row = 2; row < pascalTringleMatrix.Length; row++)
- {
- var currentLength = row + 1;
- pascalTringleMatrix[row] = new long[currentLength];
- pascalTringleMatrix[row][0] = 1;
- pascalTringleMatrix[row][currentLength - 1] = 1;
- for (int col = 1; col < currentLength - 1; col++)
- {
- var top = pascalTringleMatrix[row - 1][col];
- var topLeft = pascalTringleMatrix[row - 1][col - 1];
- pascalTringleMatrix[row][col] = top + topLeft;
- }
- }
- foreach (var row in pascalTringleMatrix)
- {
- Console.WriteLine(string.Join(" ", row));
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement