Skip to content

Instantly share code, notes, and snippets.

@umutakturk
Created October 20, 2012 12:27
Show Gist options
  • Select an option

  • Save umutakturk/3923158 to your computer and use it in GitHub Desktop.

Select an option

Save umutakturk/3923158 to your computer and use it in GitHub Desktop.

Revisions

  1. K. Umut Aktürk revised this gist Oct 20, 2012. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions binomial.cpp
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@

    using namespace std;

    int factorial(int n)
    float factorial(int n)
    {
    if (n == 1 || n == 0) {
    return 1;
    @@ -18,7 +18,7 @@ int factorial(int n)
    }
    }

    int combination(int n, int r)
    float combination(int n, int r)
    {
    return factorial(n) / (factorial(n-r) * factorial(r));
    }
    @@ -32,7 +32,7 @@ int main()

    for (r = 0; r <= n; ++r)
    {
    cout << combination(n, r) << " ";
    cout << combination(n,r) << " ";
    }

    cout << endl;
  2. K. Umut Aktürk created this gist Oct 20, 2012.
    41 changes: 41 additions & 0 deletions binomial.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    /**
    * Binomial Coefficients
    *
    * @author K. Umut Aktürk <http://umut.me>
    * @date October 20, 2012
    */

    #include <iostream>

    using namespace std;

    int factorial(int n)
    {
    if (n == 1 || n == 0) {
    return 1;
    } else {
    return n * factorial(n-1);
    }
    }

    int 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;
    }