Last active
October 17, 2019 08:52
-
-
Save snadahalli/f2179d8ca1a8cb2579cbe8c3c84bd974 to your computer and use it in GitHub Desktop.
C Program to find Binomial coefficients without using recursion
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
// C program to find the Binomial coefficient. Downloaded from www.c-program-example.com | |
#include<stdio.h> | |
void main() { | |
int i, j, n, k, min, c[20][20]={0}; | |
printf("This program is brought to you by www.c-program-example.com\n" ); | |
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"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment