0

Hello everyone!!!

I have the following pseudocode and I'm not exactly sure how/where to plug it into my code. I am still very lost concerning programing so please bear with my ignorance...:)

/* 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
}


This is my code below but from line 38, I'm not sure what to do next:

#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 = : <= ; i=i+1)
     denominator = * ;
     write code to compute numerator, along similar lines
     
     return ( ) ; write return value
}
3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by confusedndazed
0

Yeah, from line 38 everything seems to be messed up. Could you please explain more about the binomial number please. What exactly are you supposed to find?

0

you will need to set up the variable values for numerator and the denominator using 2 different for loops

and then compute numerator/denominator.. after which you send it up.

0

Hi, This is the code starting at line 38, I am supposed to plug my code into the red areas but I'm very lost, the pseudocode is in the beginning of my original post.....Thanks!

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
   }
}

Edited by confusedndazed: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.