For c++ How many possible bridge hands are there? This question is a specific ca
ID: 3710346 • Letter: F
Question
For c++
How many possible bridge hands are there? This question is a specific case of the general question: how many combinations of X items can I make out of Y items? In the case of the bridge hand, X is 13 and Y is 52. The solution is given by the following formula: Combinations(Y, X) = Y if X = 1 1 if X = Y (Combinations(Y-1, X-1) + Combinations(Y-1, X)) if Y > X > 1 Write a recursive function that calculates the number of combinations of X items that can be made from Y items. Write a driver and answer the original questions. For this exercise you should use 7 for Y and 3 for X.
Explanation / Answer
//
#include<iostream>
using namespace std;
//recursive function for combinations()
int Combinations(int y,int x)
{
//if x is 0 or x is y then return 1
if(x==0||x==y)
return 1;
//else, run recursive function calls
else
return Combinations(y-1,x-1)+Combinations(y-1,x);
}
//main function
int main()
{
//General case, i.e x items can i make out of y items
int y=7,x=3,combi;
cout<<" Y = "<<y<<" X = "<<x<<endl;
combi=Combinations(y,x);
cout<<" The Combinations are:"<<combi<<endl;
//possible bridge hands
y=52,x=13;
cout<<" Y = "<<y<<" X = "<<x<<endl;
combi=Combinations(y,x);
cout<<" The Combinations are:"<<combi<<endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.