Question
Use the following three mathematical functions (assume N >= 0): - Sum(N) = 1 + 2 + 3 + ... + N - BiPower(N) =
Use the following three mathematical functions (assume N >= 0):
- Sum(N) = 1 + 2 + 3 + ... + N
- BiPower(N) = 2N
- TimesFive(N) = 5N
1. Define recursively using your math knowledge.
a. Sum(N)
b. BiPower(N)
c. TimesFive(N)
2. Create a recursive program that prompts the user for a non-negative integer N and outputs. Describe any input constraints in the opening comment of your recursive methods.
a. Sum(N)
b. BiPower(N)
c. TimesFive(N)
d. Fib(N)
The Fibonacci sequence is the series of integers 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 ... See the pattern? Each element in the series is the sum of the preceding two elements. Here is a recursive definition the Fibonacci sequence:
Fib(N) =
N if N = 0 or 1
Fib(N - 2) + Fib(N - 1) if N > 1
[ Extra Credit]
Write a nonrecursive version of the method Fib.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started