Question: c++ Short coding questions: Write an iterative (with loop) function power1 to compute x n for n>=0. Write the function prototype, header and body for

c++

Short coding questions:

  1. Write an iterative (with loop) function power1 to compute xn for n>=0. Write the function prototype, header and body for the function. It takes two parameters x and n (both are integers) and return the value of xn.

  1. Write a recursive function power2 to compute xn by using the following recursive formulation:

x0=1;

xn=x*xn-1 if n>0

  1. Write a recursive function power3 to compute xn by using the following recursive formulation:

x0=1;

xn=xn/2*xn/2 if n>0 and n is even

xn=x* xn/2* xn/2 if n>0 and n is odd

  1. How many multiplications will each of the functions power1, power2, and power3 perform when computing 332? 319?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!