So I have to write a program that prints out the eleven 10th order binomial coefficients. I came across this code that does what I needed, but I'm trying to understand why it works.
#include<stdio.h>
int binomialCoeff(int n, int k)
{
if(k == 0)return 1;
if(n <= k) return 0;
return (n*binomialCoeff(n-1,k-1))/k;
}
int main()
{
int k;
for(k=10;k>=0;k-=1)
{
printf("%d\n", binomialCoeff(10, k));
}
I get why the int main part works, I just don't get how the binomialCoeff calculation is made. I'm relatively new to all of this coding stuff, so thank you for the help!