From f6ae0721a3ec9062b493c76412b1574336fe8f6e Mon Sep 17 00:00:00 2001 From: prateeknanda10 <51031434+prateeknanda10@users.noreply.github.com> Date: Sun, 19 Jul 2020 12:56:11 +0530 Subject: [PATCH] Update Pascal's Triangle.cpp the one that you already had printed the output wihtout the starting spaces. like: for n=4-> 1 11 121 1331 however, the required output was in this format: 1 1 1 1 2 1 1 3 3 1 --- PATTERN/Pascal's Triangle.cpp | 47 ++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/PATTERN/Pascal's Triangle.cpp b/PATTERN/Pascal's Triangle.cpp index 5e928cc..27e6353 100644 --- a/PATTERN/Pascal's Triangle.cpp +++ b/PATTERN/Pascal's Triangle.cpp @@ -1,24 +1,31 @@ #include - +#include using namespace std; +long fact(long n){ + int i, fact = 1; + for(i = n; i>1; i--) + fact *= i; + return fact;//factorial of given number +} +long nCr(long n, long r){ + long nume = 1, i; + for(i = n; i>r; i--) + nume *= i; + return long(nume/fact(n-r));//generate result of nCr +} +void genPascalsTriangle(long n){ + for(int i = 0; i> n; + genPascalsTriangle(n); +} -int main() -{ - int n,i,j; - cin>>n; - - int a[n][n]; - for(i=0;i