# computer science

Algorithm for Binomial Numbers
Binomial numbers (or binomial coefficients) are important positive integers that arise frequently in computing and mathematics. A function to compute binomial coefficients will have two inputs: n and k. The corresponding coefficient is written as nCk.

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

Because binomial numbers are integers, the return type should be int, and the two parameters, n and k, are also integers.
We have used the notation
1*2*…*k

to indicate the product of consecutive numbers. For example,

1*2*…*5

is actually

1*2*3*4*5 = 120

Similarly,

6*7...*10 = 6*7*8*9*10 = 30,240

Part of the challenge in this exercise is to figure out how to compute this product. You should review the for loop in module 3, and recall how for loops are written in C++. Also review the programming exercise on exponentiation in module 3.
You can use integer division in line 7 above—it turns out that if numerator and denominator are computed as shown above, denominator will always evenly divide numerator.
To test this function, you must write a driver (in the code template given below, the driver is the main function).

You should design a suitable test suite and test your program using it. The test suite is part of the materials that you will be submitting.

Code Template for Exercise 1
/****************************************************/
/* File: name of your file with the source code */
/* */
/* Created by: give your name */
/* Date: give the date */
/* */
/* 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 = ?? Write the function call ;

cout << "Binomial number " << n << "C" << k
<< " = " << result << endl ;

return (0) ;
}

// ********************************************************

binomial(int n, int k)

/* Computes the binomial coefficient nCk */
/* */
/* Inputs: */
/* n, k (integers) */
/* */
/* Output: */
/* binomial coefficient nCk (integer) */<![endif]>

{
int numerator, denominator ;
int i ; // needed to compute numerator & denominator <![endif]>

if (?? Write if-test)
{
return(??) ;
}
else
{
denominator = ?? ; // initial value <![endif]>

for (i = ?? ; i <= ?? ; i = i+1)
denominator = ?? * ?? ; <![endif]>

write code to compute numerator, along similar lines<![endif]>

return (??) ;
} // else
}

1. Heh i have thes ame problem

posted by Bobby
2. really nice 10Q a lot

posted by moges
3. ou need to perform the following actions for this CheckPoint assignment:

- Modify the Inventory Program by adding a button to the GUI that allows the user to move to the first item, the previous item, the next item, and the last item in the inventory. If the first item is displayed and the user clicks on the Previous button, the last item should display. If the last item is displayed and the user clicks on the Next button, the first item should display.

- Add a company logo to the GUI using Java graphics classes.

posted by HOLLA

## Similar Questions

1. ### C++ Algorithms

Binomial numbers (or binomial coefficients) are important positive integers that arise frequently in computing and mathematics. A function to compute binomial coefficients will have two inputs: n and k. The corresponding
2. ### math

express this in binomial: 2 4ez (4e-z) the 2 is the square.. can anyone teach me how to do this??? I'm a little unsure what your question is asking for here. Ordinarily, a binomial is an expression with two variables and some
3. ### Math

Rules on multiplying Monomial to monomials ; Monomial to Binomial : Binomial to Binomial ; Binomial to Trinomial ?
4. ### algebra 2

this binomial can be factored as the product of a binomial and trinomial. Enter the binomial factor. 64y^15 + 125
5. ### Binomial

Independent samples of n1 = 400 and n2= 400 observations were selected from binomial populations 1 and 2, and x1 = 100 and x2 = 127 successes were observed. What is the best point estimator for the difference ( p1-p2) in the two
6. ### binomial

Independent samples of n1 = 400 and n2= 400 observations were selected from binomial populations 1 and 2, and x1 = 100 and x2 = 127 successes were observed. Calculate the approximate standard error for the statistic, the point
7. ### Algebra Question~!

Suppose you divide a polynomial by a binomial. How do you know if the binomial is a factor of the polynomial? Create a sample problem that has a binomial which IS a factor of the polynomial being divided, and another problem that
8. ### algebra

the binomial 8y^12+z^6 can be factored into a binomial and a trinomial. the binomial factor is (2y^4+z^2). whats the trinomial?
9. ### math

Create a quadratic polynomial function f(x) and a linear binomial in the form (x − a). Part 1. Show all work using long division to divide your polynomial by the binomial. Part 2. Show all work to evaluate f(a) using the
10. ### Algebra2/trig

Hi, I can't figure out what I'm supposed to do on this problem. Could someone help? Thanks. Find the coefficient of a of the term in the expansion of the binomial. Binomial (x^2+3)^12 Term ax^8

More Similar Questions