Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Following function mypow() computes the nth power of x. This function is called

ID: 3764911 • Letter: F

Question

Following function mypow() computes the nth power of x. This function is called from the main. Each line of the program mypow() is numbered. Sequence of line numbers for execution of the function mypow() when n=2 is 1,2,3 ( done at compile time),4,5,4,5,4,6.

Following is the recursive definition of the function mypowrec() which also computes the nth power of x:

(a) Give the sequence of the line numbers for execution when n=2.

(b) Indicate why the program will go into a loop if line 5 and line 6 are deleted (hint: when n=1 what happens to the computation on line 10?)

(c) In line 8 there are two function mypowrec(). When n==4 how many times the mypowrec() on the left in line 8 will be invoked before the one on the right is invoked.

Thank you!!

Explanation / Answer

(a) 1,2,3,5,7,8,1,3,5,6,1,3,5,6

(b) because at some point of time for some value of n, n may become 1 and if it is deleted then we wont get required results.

(c)2