Skip to content

Instantly share code, notes, and snippets.

@unilecs
Created March 17, 2019 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unilecs/aa9304a89fce0e37fc18c3a633a0fcbb to your computer and use it in GitHub Desktop.
Save unilecs/aa9304a89fce0e37fc18c3a633a0fcbb to your computer and use it in GitHub Desktop.
Задача: Треугольник Паскаля
using System;
public class Program
{
public static void Main()
{
Console.WriteLine("UniLecs");
DisplayPascalTriangle(3);
}
private static void DisplayPascalTriangle(int n)
{
int[,] arr = new int[n, n];
// Prepare matrix
arr[0, 0] = 1;
for (int i = 1; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (j == 0 || j == i)
{
arr[i, j] = 1;
}
else
{
arr[i, j] = arr[i - 1, j - 1] + arr[i - 1, j];
}
}
}
// Display matrix
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (arr[i, j] > 0)
{
Console.Write(arr[i,j] + " ");
}
}
Console.WriteLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment