Joined: Thu Apr 09, 2009 2:39 am Posts: 3 Has thanked: 0 time Have thanks: 0 time
I have to take c++ as part of my degree plan but I can't figure out this language. Can anyone help with this code PLEASE?
Code:
/* Program to compute binomial coefficients */ /* */ /* Inputs: (keyboard) */ /* Two positive integers (n & k) */ /* */ /* Output: */ /* Corresponding binomial coefficient (nCk) */ /* */ /* Algorithm: see attached description */ /****************************************************/ #include <iostream> using namespace std ; int binomial(int n, int k) ; // function prototype
int main() { int n, k ; // parameters for the binomial number int result ; cout << endl ; // read in n & k cout << "Enter n (positive integer) : " ; cin >> n ; cout << "Enter k (positive integer) : " ; cin >> k ; result = NEED TO WRITE FUNCTION CALL HERE cout << "Binomial number " << n << "C" << k << " = " << result << endl ; return (0) ; } // ******************************************************** int binomial(int n, int k) /* Computes the binomial coefficient nCk */ /* */ /* Inputs: */ /* n, k (integers) */ /* */ /* Output: */ /* binomial coefficient nCk (integer) */ { int numerator, denominator ; int i ; // needed to compute numerator & denominator
ALL THIS STUFF NEEDS TO BE CHANGED
if ( ? ) Write if-test { return( ? ) ; Write return value } else { denominator = ? ; Write initial value for (i = ? ; i <= ? ; i = i+1) denominator = ? * ? ; Write code to compute numerator, along similar lines return ( ? ) ; Write return value } }