Created
September 9, 2020 13:46
-
-
Save Quentin18/f3475d0ef80cbfd1c9fce5dd2d3daaba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Pascal's triangle | |
https://en.wikipedia.org/wiki/Pascal%27s_triangle | |
Quentin Deschamps, 2020 | |
*/ | |
#include <iostream> | |
using namespace std; | |
long facto(long n) | |
{ | |
if (n == 0) return 1; | |
return n * facto(n - 1); | |
} | |
long binom(long n, long k) | |
{ | |
return facto(n) / (facto(k) * facto(n - k)); | |
} | |
int main() | |
{ | |
long nmax, n, k; | |
cout << "Number of rows : "; cin >> nmax; | |
for (n = 0; n < nmax; n++){ | |
for (k = 0; k <= n; k++){ | |
cout << binom(n, k) << " "; | |
} | |
cout << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment