Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace _02_Pascal_Triangle
- {
- class Program
- {
- static void Main()
- {
- int rowsCount = int.Parse(Console.ReadLine());
- var previousRow = new List<int>();
- for (int i = 1; i <= rowsCount; i++)
- {
- var rows = new int[i];
- rows[0] = 1;
- if (i > 1)
- {
- rows[^1] = 1;
- }
- if (i == 3)
- {
- rows[1] = 2;
- }
- if (i > 3)
- {
- int counter = 0;
- for (int k = 1; k < i - 1; k++)
- {
- rows[k] = previousRow[counter] + previousRow[k];
- counter++;
- }
- counter = 0;
- }
- previousRow.Clear();
- for (int j = 0; j < rows.Length; j++)
- {
- previousRow.Add(rows[j]);
- }
- foreach (var number in rows)
- {
- Console.Write(number + " ");
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement