Skip to content

Instantly share code, notes, and snippets.

@Quentin18
Created September 9, 2020 13:46
Show Gist options
  • Save Quentin18/f3475d0ef80cbfd1c9fce5dd2d3daaba to your computer and use it in GitHub Desktop.
Save Quentin18/f3475d0ef80cbfd1c9fce5dd2d3daaba to your computer and use it in GitHub Desktop.
/*
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