Skip to content

Commit

Permalink
DP Solution for Binomial Coefficient
Browse files Browse the repository at this point in the history
  • Loading branch information
ranganeeraj authored Oct 1, 2023
1 parent cabb853 commit 6273440
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 6273440

Please sign in to comment.