Dain1234 / Design-and-analysis-algorithm

0 stars 0 forks source link

Binomial coefficient #28

Open Dain1234 opened 1 year ago

Dain1234 commented 1 year ago

include

void main() { int i, j, n, k, min, c[20][20]={0};
printf("\n Enter the value of n: ");
scanf("%d", &n);
printf("\n Enter the value of k: ");
scanf("%d", &k); if(n >= k) {
for(i=0; i<=n; i++) {
min = i<k? i:k; for(j = 0; j <= min; j++) { if(j==0 || j == i) { c[i][j] = 1; } else { c[i][j] = c[i-1][j-1] + c[i-1][j]; } } } printf("%d\t",c[n][k]); printf("\n"); } else { printf("\n Invalid input \n Enter value n>=k \n"); } }

Dain1234 commented 1 year ago

Enter the value of n: 10

Enter the value of k: 5 252