Project3-Q1 - /values of X and Y in every single trace if(X...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
#include<iostream> using namespace std; u int Combinations(int Y, int X, int level); //function prototype / int main() { int X=4; //initializes X to 4 int Y=8; //initializes Y to 8 int level=1; //initializes the recursive level to 1 / cout<<"The number of total combinations is "<<Combinations(Y,X,level)<<endl; //here I call on my Combinations function, which is recursive, and //enter the parameters as needed system("pause"); return 0; } int Combinations(int Y, int X, int level) //function implementation { cout<<"Recursive Level: "<<level<<endl; cout<<"Y = "<<Y<<", X = "<<X<<endl; //outputs a trace of each recursive level to the screen, as well as the
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: //values of X and Y in every single trace if(X == 1) //if X=1, the value of Y is returned to be added in the return Y; //recursive call else if(X == Y) //if X=Y, the value of 1 is returned to be added in the return 1; //recursive call else return (Combinations(Y-1,X-1,level+1)+Combinations(Y-1,X,level+1)); //If neither of the above scenarios happen anymore, the program adds //everything that has been done in each recursive level until it //obtains a result, which would be the total number of combinations, //in this case 70. }...
View Full Document

Ask a homework question - tutors are online