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:
- 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.
- Write a recursive function power2 to compute xn by using the following recursive formulation:
x0=1;
xn=x*xn-1 if n>0
- 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
- 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
Get step-by-step solutions from verified subject matter experts
