Question: Question to be done in C. Use the three recursive functions discussed in class for raising a number to a power to compute (1.12)631. For
Question to be done in C. Use the three recursive functions discussed in class for raising a number to a power to compute (1.12)631. For each function, your program should print out the result of exponentiation and the number of times the function is called. Also print the average execution times. Below are the hint and recursive function.
double fpow(float a, int n) { if (n == 0) return 1; else { if( n % 2 == 0) { return fpow(a, n/2) * fpow(a, n/2); } else { return a * fpow(a, n/2) * fpow(a, n/2); } } } double fpww(float a, int n) { if (n == 0) return 1; else { double b = fpww(a, n/2); if( n % 2 == 0) { return b*b; } else { return a * b * b; } } } double fpwww(float x, int n) { float m; if (n == 0) return 1; if (n % 2 == 0) { m = fpwww(x, n / 2); return m * m; } else return x * fpwww(x, n - 1); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
