C Program to find Binomial Integers without using recursion.
Binomial coefficients are positive integers that are coefficient of any term in the expansion of (x + a) the number of combination’s of a specified size that can be drawn from a given set.
There are many ways to compute the Binomial coefficients. Like,
In this post we will be using a non-recursive, multiplicative formula.
The program is given below:
// 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");
}
}
Sample output

5 comments on “C Program to find Binomial Coefficients”
hey there u ppl have done a great job with the website….!!! but in the program above i found these errors-
1)Line 17: error: conio.h: No such file or directory
In function 'main':
2)Line 4: warning: return type of 'main' is not 'int'
just two….
anyway keep up the great job!!! ๐ ='
ignore the warning sorry…. ๐
that makes it just one error
No problem. That's fixed now though ๐
Thanks.
a is undeclared… Even though I declared it on my program, it didn’t work..
Hello PiXan,
Thanks for pointing this out. I could not respond sooner, apologies for that.
It was a typo. it’s supposed to c and not a there. I have fixed the program, tested and added the sample output as well.
Thanks again for your support.