Pascal triangle Python code example

Example 1: how to find the ith row of pascal's triangle in c

#include <stdio.h>
#include <stdlib.h>

int main()
{
  int N;

  scanf("%d", &N);
  int pascalArray[N + 1][N + 1];
  int i, j;
  if(0 <= N && N <= 20)
  {
      for (i = 0; i < N + 1; i++)
      {
        for(j = 0; j <= i; j++)
        {
            if(j == 0 || j == i)
                pascalArray[i][j] = 1;
            else
                pascalArray[i][j] = pascalArray[i-1][j-1] + pascalArray[i-1][j];
            if (i == N)
                printf("%d ", pascalArray[i][j]);
        }
      }
  }
  return 0;
}

Example 2: pascal's triangle python reverse function

def pascal_triangle(n):
   	trow = [1]
   	y = [0]
   	for x in range(max(n,0)):
      	print(trow)
      	trow=[l+r for l,r in zip(trow+y, y+trow)]
   	return n>=1
pascal_triangle(6)

Example 3: pascal's triangle python

def solve(A):
    pascals_triangle = []

    for i in range(A):
        pascals_triangle.append([1]*(i+1))
  
    for i in range(2,A):
        for j in range(1,i):
            pascals_triangle[i][j] = pascals_triangle[i-1][j-1] + pascals_triangle[i-1][j]

    return pascals_triangle