Explore BrainMass
Share

Some Function Calls and their return values

This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

Trace the following program and give the return value for each function call:

int h (int b, int n)
{
if ( n = = 0)
return 1;
else
return(b * h(b, n-1));
}

(a). What are values for h(), assuming function calls as follows:
i. h(5,3)
ii. h(3,5)
iii. h(2,2)
(b). Describer the action of the function. What is the function in the <cmath> library that performs a similar calculation?

© BrainMass Inc. brainmass.com March 21, 2019, 6:52 pm ad1c9bdddf
https://brainmass.com/computer-science/programming-languages/function-calls-return-values-271452

Solution Preview

(a). What are values for h(), assuming function calls as follows:
i. h(5,3)
ii. h(3,5)
iii. h(2,2)

Answer ----
a. h(5,3) will return 125.

b. h(3,5) will return 243

c. h(2,2) will return 4.

(b). Describer the action of the ...

Solution Summary

The solution tells in detail why and what the function is going to return.

$2.19