C++ program

C(n,k) can be rewritten as n(n-1)(n-2)…(n-k+1)/k!. Implement a program that computes C(n,k) based on this formula, using ints. Hint: the numerator is obviously an iteration, but what is the iteration variable?). Repeat the questions from above. This program is obviously better than 1 since it works on more input values, but how does it compare to 1 efficiency-wise? An appropriate measure of efficiency here would be the number of multiplies.

Use property (P2) to make your solution more efficient (in some cases).

!!!!!!!!!!!!!!!!!!!!There are better algorithms that require only integer arithmetic, though we do not have enough C knowledge yet to implement these. If you wish to learn more, you can look up dynamic programming algorithms (and arrays to implement them).!!!!!!!!!!!!

## Expert Answer

#include <iostream>

Don't use plagiarized sources. Get Your Custom Essay on

Question & Answer: C++ program…..

GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS $13/PAGE

using namespace std;

int main() {

int n;

int k;

int numarator=1;

int denominator=1;

int result;

cout<<“Enter the value of n” <<endl;

cin>>n;

cout<<“Enter the value of K”<<endl;

cin>>k;

for(int i=k;i>=1;i–)

{

numarator=numarator*n;

n–;

denominator=denominator*i;

}

result=numarator/denominator;

cout<<“the vlaue is”<<result;

}