Hello people, this is my second attempt to get help for the same code. First post is unsolved. I apologize for any confusion in my posts but I'm confused myself so it's somewhat hard for me to properly explain that which I don't even understand....:$....
I have been given the following information:
/* pseudocode for Binomial
Coefficients */
int binomial(int n, int k)
{
If (n < k) Then return (0)
Else
{
Set denominator = 1*2*...*k
Set numerator = (n-k+1)*(n-k+2)*...*(n-1)*n
return (numerator / denominator)
} // else
End if
}
Here is my code thus far, sorry if it's really bad:
#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 = binomial(n,k);
cout << "Binomial number " << n << "C" << k
<< " = " << result << endl ;
return (0) ;
}
int binomial(int n, int k)
{
int numerator, denominator ;
int i ; // needed to compute numerator & denominator
if (n < k) Then
{
return (0) ;
}
else
{
denominator = 1*2*...*k ;
for ( i = k : <= n ; i=i+1)
denominator = * ;
numerator = (n-k+1)*(n-k+2)*...*(n-1)*n
return (numerator / denominator) ;
}
I am very new and lost so please bear with me in your replies, as I still may not "get it".....Thanks!!