Data structures
1.Choose the simple recursive function that will raise a number to an exponential power by
multiplication operations.
2.In the following recursive function, which line(s) represent the base case?
void PrintIt( /* in */ int n ) // Line 1
{ // Line 2
if (n > 0) // Line 3
{ // Line 4
cout << “Again” << endl; // Line 5
PrintIt(n – 1); // Line 6
} // Line 7
else // Line 8
cout << n << endl; // Line 9
}
lines 5-6
lines 5-9
lines 6-9
line 9
3.In the following recursive function, which line(s) represent the general (recursive) case?
void PrintIt( /* in */ int n ) // Line 1
{ // Line 2
if (n > 0) // Line 3
{ // Line 4
cout << “Again” << endl; // Line 5
PrintIt(n – 1); // Line 6
} // Line 7
else // Line 8
cout << n << endl; // Line 9
}
lines 5-6
lines 5-9
lines 6-9
line 9
4.Given the recursive function
int Sum( /* in */ int n )
{
if (n < 8)
return n + Sum(n + 1);
else
return 2;
}
what is the value of the expression Sum(5) ?
5
13
20
None–the result is infinite recursion.
5.If the following function is called with a value of 73 for n, what is the resulting output?
void Func( /* in */ int n )
{
if (n > 0)
{
Func(n / 5);
cout << n % 5;
}
}
143
243
342
None of the above

+1 862 207 3288 