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

u.lb/webapps/blackboard/content/listContent.jsp?course id-17813 1&content; ids c

ID: 3880066 • Letter: U

Question

u.lb/webapps/blackboard/content/listContent.jsp?course id-17813 1&content; ids c++practice Programming assignment 0 DEADLINE:Monday 29Januarynclass Implement the two methods for computing the Fibonacci sequence, iterative and recursive U of x, x+1 For each computation measure the time it take sing both methods compute fibonacci y x is betwee 0 where x is the number that takes a hardware s Plot x versus the time it takes to compute fibonacci o#x for both iterative and recursive Submit your code and the plots in one document Your code should look ke #include #include long long fib(long long n) ( /write your iterative fibonacci code here long long rfib(long long n) /write your recursive fibonacci code here int main(int argc, char razgv) long long x,y clock t start,end

Explanation / Answer

Answer:

Iterative code:

#include <ctime>

#include<iostream>
using namespace std;
int main()
{

int n, first = 0, second = 1, next, c;

cout<<"Enter the number of terms ";
cin>>n;

cout<<"First %d terms of fibonacci series are :- <<n;

for ( c = 0 ; c < n ; c++ )
{
if ( c <= 1 )
next = c;
else
{
next = first + second;
first = second;
second = next;
}
cout<<" "<<next);
}

return 0;
}

Recursive:

#include <ctime>

#include<iostream>
using namespace std;

int main()

{

int n, fibo;

cout<<"Please enter the value of n: ";

cin>>n;

fibo = fib(n);

return 0;

}

Please provide your valuable feedback.