ASSIGNMENT #5 (Stefan Ikonomovski)
===========================================
Problem statement:
------------------
Write a C program which calculates Binomial Coeficient of two numbers
"n" and "k" according to the formula
n!
---------- assuming n > k.
k!(n-k)!
Reminder:
The factorial of a number "n" is the product
n! = n * (n-1)!
where 1! = 1 and
0! = 1 by definition.
(ex. 5! = 5 * 4! or 5! = 5 * 4 * 3 * 2 * 1 = 120)
Instructions:
-------------
You should create a function
int BinCoef(int, int);
which accepts the numbers "n" and "k" as an input parameters and returns
the needed result. You should also create a function
int Factorial(int);
which accepts a number as an input and returns it's factorial as an output,
and use it in a recursive fashion.
Your program should read in a loop different values from an input file.
The input will have two numbers "n" and "k" per line. Terminate reading
with the value -1.
Test your program with the following pairs of numbers:
7 3
8 2
9 5
10 4
10 6
-1 -1
Accordingly, your output might look like:
n k BinCoef
-------------------------
7 3 value
8 2 value
9 5 value
10 4 value
10 6 value
Try to make the most efficient code (BONUS 10%).
Eg.
12*11*10*9*8*7! 12*11*10*9*8
BinCoef(12, 5) = ----------------- = --------------
5! * 7! 5!