Question: 1 Coding Problem: 1. Write a C program that asks the user to enter values for r and n, calls a recursive function, called power

1 Coding Problem: 1. Write a C program that asks the user to enter values for r and n, calls a recursive function, called power (x, n), to compute x, and then displays the value returned by the function. The power function, i.e., power (x, n), should be efficient enough to calculate In faster instead of multi- plying the value i.e., x n times. Notice that if n is a power of 2, then x" can be computed by squaring. For example, x is the square of r, so r4 can be computed using only two multiplications instead of three. As it happens, this technique can be even used when n is not a power of 2. Therefore, the recursive function can be defined as below: If n is even, use the formula r" = (x"/2) If n is odd, use the formula r" = x x xn-1 If n = 0, return 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
