# HW #6 - is a valid call what is its value If not explain...

This preview shows pages 1–2. Sign up to view the full content.

David Carothers CS 230 10/24/07 Homework # 6 Excercises 2. What is a base case? The case in which the solution is given directly. 3. What is a recursive case? The case in which the base class is derived from. Also known as the general case. 7. Consider the following recursive function: Int mystery(int number) { If(number == 0) Return number; Else Return(number + mystery(number-1)); { a. Identify the base case Number + number-1= some other number b. Identify the general case Number + number-1= some other number c. What valid values can be passed as parameters to the function mystery? d. If mystery(0) is a valid call, what is its value? If not, explain why. 0 e. If mystery(5) is a valid call, what is its value? If not, explain why. 15 f. If mystery(-3)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: is a valid call, what is its value? If not, explain why. Invalid call because its negative. 8. Consider the following recursive function: Void functRec(int u, char v) { If(u == 0) Cout <<v; Else if(u == 1) Cout<<static_cast<char>(static_cast<int>(v) +1); Else funcRec(u-1, v); } a. Identify the base case n 2 *v+n b. Identify the general case n((n*v)+1) c. What is the output of the following statement? funcRec(5,’A’); => ( 11. Consider the following function: Int Func(int x) { If(x==0) Return 2; Else if(x==1) Return 3; Else Return (Func(x-1) + Func(x-2)); } a. cout<<Func(0)<<endl; => 2 b. cout<<Func(1)<<endl; => 3 c. cout<<Func(2)<<endl; => 5 d. cout<<Func(5)<<endl; => 21...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

HW #6 - is a valid call what is its value If not explain...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online