Skip to content

Commit

Permalink
Merge pull request #1924 from ranganeeraj/patch-12
Browse files Browse the repository at this point in the history
DP Solution for Binomial Coefficient
  • Loading branch information
shoaibrayeen authored Oct 2, 2023
2 parents 94795e5 + 6273440 commit 97d15fb
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Dynamic Programming/Binomial Coefficient/SolutionByNeeraj.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <iostream>
using namespace std;

int binomialCoeff(int n, int k) {
int C[k+1];
memset(C, 0, sizeof(C));

C[0] = 1;

for (int i = 1; i <= n; i++) {
for (int j = min(i, k); j > 0; j--)
C[j] = C[j] + C[j-1];
}
return C[k];
}

int main () {
cout << "\nEnter n\t:\t";
int number;
cin >> number;
cout << "\nEnter k\t:\t";
int k;
cin >> k;
cout <<"\nThe result is\t:\t" << binomialCoeff(number, k);
cout << endl;
return 0;
}

0 comments on commit 97d15fb

Please sign in to comment.