Skip to content

Instantly share code, notes, and snippets.

@umutakturk
Created October 20, 2012 12:27
Show Gist options
  • Save umutakturk/3923158 to your computer and use it in GitHub Desktop.
Save umutakturk/3923158 to your computer and use it in GitHub Desktop.
Binomial Coefficients
/**
* Binomial Coefficients
*
* @author K. Umut Aktürk <http://umut.me>
* @date October 20, 2012
*/
#include <iostream>
using namespace std;
float factorial(int n)
{
if (n == 1 || n == 0) {
return 1;
} else {
return n * factorial(n-1);
}
}
float combination(int n, int r)
{
return factorial(n) / (factorial(n-r) * factorial(r));
}
int main()
{
int n, r;
cout << "Enter the n value of (x+y)^n: ";
cin >> n;
for (r = 0; r <= n; ++r)
{
cout << combination(n,r) << " ";
}
cout << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment