-
-
Save unilecs/aa9304a89fce0e37fc18c3a633a0fcbb to your computer and use it in GitHub Desktop.
Задача: Треугольник Паскаля
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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