Created
October 20, 2012 12:27
-
-
Save umutakturk/3923158 to your computer and use it in GitHub Desktop.
Binomial Coefficients
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
/** | |
* 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