Question: Write two procedures for producing the nth Fibonacci number when the number n is given as input. In one procedure, use a for loop and
Write two procedures for producing the nth Fibonacci number when the number n is given as input. In one procedure, use a for loop and produce the answer using iteration. In the second version use recursion. The input argument and return value should be of type long. Use the following definition of Fibonacci numbers: F0 = F1 = 1, and Fn = Fn?1 + Fn?2 for all n ? 2. Have your procedure return ?1 if the input argument is negative. Dont worry about overflow. and then write a main to test the Fibonacci procedures you created in the last code. Use it to evaluate F20, F30, and F40. PLease in C++
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
