Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PascalTriangle
//g++ 7.4.0 //write and test a function that creates Pascal's Triangle in the square matrix passed to it; //credit for factorial function and combination function codes goes to John R. Hubbard, University of Richmond //Pascal Triangle function and test driver codes are created by Rezaul Hoque on June 30,2021; contact: jewelmrh@yahoo.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; #include <iostream> using namespace std; int fact(int ); int comb(int, int); void pascal(int [][5], int); void pascal(int b[5][5], int n){ for(int i=0;i<n;i++){ for(int j=0;j<i+1;j++) b[i][j]=comb(i,j); } for(int i=0;i<n;i++){ for(int j=0;j<n;j++) cout<<" "<<b[i][j]; cout<<endl; } } int fact(int n){ if (n<0) return 0; int f= 1; while(n>1) f *= n--; return f; } int comb(int n, int k){ return(fact(n)/(fact(k)*fact(n-k))); } int main(){ int n=5; int b[5][5]={{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}}; pascal(b,n); return 0; }
run
|
edit
|
history
|
help
0
break.cpp
TraiectorieIdeala
Metodos 2- programa3
PrintShape
Test 9(2020)
Algoritm(prelucrare cifre)
Zahra_matrix
VecScalMultiOpLaod
YesToDafT
Const Return Test