Quiz #08 (Most important, final exam question #4)

Hello dear friends! A quick tutorial on how to solve the fourth question of the exam. I hope you find this very useful and thanks for watching!

Code:

#include <iostream>
using namespace std;

int fibonacci(int n)
{
int fib=1, pre=0;
for(int accu=0; accu<n; accu++)
{
fib+=pre;
pre=fib-pre;
} return fib;
}

int main()
{
int res,n;
cout<<“Dame número “<<endl;
cin>>n;
res=fibonacci(n);
cout<<“Tu fibonacci es “<<res<<endl;
return 0;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s