8000 Adding Pascal's triangular matrix algorithm · AllAlgorithms/python@577449f · GitHub
[go: up one dir, main page]

Skip to content

Commit 577449f

Browse files
authored
Adding Pascal's triangular matrix algorithm
1 parent 7f12f2c commit 577449f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

algorithms/math/pascal_matrix.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Credit : LyFromQixing a.k.a QueenLy
2+
# Date : 12 November 2021
3+
# Description : A program that accepts N input and writes a Pascal's triangular matrix of size N*N.
4+
5+
def pascal_matrix(N):
6+
7+
# Creating Pascal's Triangular Matrix
8+
matrix = [[1 for i in range(N)] for j in range(N)]
9+
for i in range(1, N):
10+
for j in range(1, N):
11+
matrix[i][j] = (matrix[i-1][j] + matrix[i][j-1])
12+
13+
# Showing matrix
14+
for i in range(N):
15+
print()
16+
for j in range(N):
17+
print(matrix[i][j], end=" ")
18+
19+
N = int(input("Insert N: "))
20+
21+
pascal_matrix(N)

0 commit comments

Comments
 (0)
0