Answer to Question #21297 in C++ for ALaa

Question #21297
Write a C++ code that implements a recursive function that solves the Fibonacci theory. Your program should ask the user to enter a number then you'll show him the Fibonacci of the entered number.
1
Expert's answer
2012-12-27T10:27:54-0500
#include <iostream>

using namespace std;

int fun(int n)
{
int g[1000];
g[0]=0;
g[1]=1;
g[2]=1;


& for(int j=3;j<=n;j++)
& {
g[j]=j;

g[j]=g[j-1]+g[j-2];

& cout<<g[j]<<"& ";
& }
}
int main()
{
int g[1000];
g[0]=0;
g[1]=1;
g[2]=1;

cout<<"please enter n"<<endl;
int n;
cin>>n;
cout<<g[0]<<" "<<g[1]<<" "<<g[2]<<" ";
fun(n);
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Assignment Expert
28.12.12, 14:34

You're welcome. We are glad to be helpful. If you really liked our service please press like-button beside answer field. Thank you!

Alaa
28.12.12, 13:49

thanx for your great help,,i understand the concept finally

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS