Computer Science, asked by DekhMc, 1 year ago

write a program to print Pascal's triangle. ..15 rows. ​

Answers

Answered by mikun24
3

Answer:

Pascal triangle in C

#include <stdio.h>

long factorial(int);

int main()

{

int i, n, c;

printf("Enter the number of rows you wish to see in pascal triangle\n");

scanf("%d",&n);

for (i = 0; i < n; i++)

{

for (c = 0; c <= (n - i - 2); c++)

printf(" ");

for (c = 0 ; c <= i; c++)

printf("%ld ",factorial(i)/(factorial(c)*factorial(i-c)));

printf("\n");

}

return 0;

}

long factorial(int n)

{

int c;

long result = 1;

for (c = 1; c <= n; c++)

result = result*c;

return result;

}

Answered by blossomag
3

Answer:

Method 1 ( O(n^3) time complexity )

Number of entries in every line is equal to line number. For example, the first line has “1”, the second line has “1 1”, the third line has “1 2 1”,.. and so on. Every entry in a line is value of a Binomial Coefficient. The value of ith entry in line number line is C(line, i). The value can be calculated using following formula.

C(line, i) = line! / ( (line-i)! * i! )

A simple method is to run two loops and calculate the value of Binomial Coefficient in inner loop.

Similar questions