Assignment 5 ============== T.A : Stefan Mail to : HCAE on MUSICB (all other destinations will be IGNORED) Send your 'C' source file, your data and output to your code HC-- on MUSICB. Then E-Mail both to HCAE. To get credit for your assignments they MUST by mailed from your own HC-- code - that's how we keep track of all the students in the class. Due : 15 November 1997 Weight : 35
Problem statement:
------------------
Write a C program that calculates Binomial Coefficient 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!