Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write an iterative C++ function that inputs a nonnegative integer n and retur

ID: 3775242 • Letter: 1

Question

1. Write an iterative C++ function that inputs a nonnegative integer n and returns the nth Fibonacci number.
2. Write a recursive C++ function that inputs a nonnegative integer n and returns the nth Fibonacci number.
3. Compare the number of operations and time taken to compute Fibonacci numbers recursively versus that needed to compute them iteratively.
4. Use the above functions to write a C++ program for solving each of the following computational problems.
I. Find the exact value of f100, f500, and f1000, where fn is the nth Fibonacci number. What are times taken to find out the exact values?
II. Find the smallest Fibonacci number (1) greater than 1,000,000, and (2) greater than 1,000,000,000.
III. Find as many prime Fibonacci numbers as you can. It is unknown whether there are infinitely many of these. Find out the times taken to find first 10, 20, 30, 40…up to 200 and draw a graph and see the pattern.

Explanation / Answer

1)


#include<iostream.h>
#include<conio.h>
#include<stdio.h>

void fib(int number)
{
if(0<=number<=1)
cout<<number;
else
cout<<(fib(number-1)+fib(number-2));
}

void main()
{int num;
cout<<"Please enter the number for which you want the fibonnaci series");
cin>>num;
fib(num);
}