Question: Write a C++ program called power.cpp to compute 2 n for a nonnegative integer n. In this program, you have to develop a recursive function
Write a C++ program called power.cpp to compute 2n for a nonnegative integer n. In this program, you have to develop a recursive function to calculate it. And also, you cant use a library in the program.
For the problem, you can assume that the user always enter a correct integer number which is great than or equal to zero.
[Hint: Use the formula: 2n = 2n-1 + 2n-1 for the recursive function.]
The following presents a sample run of the C++ program.
Enter a number: 3
Result: 8
This is another sample run.
Enter a number: 0
Result: 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
