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; }
Comments
You're welcome. We are glad to be helpful. If you really liked our service please press like-button beside answer field. Thank you!
thanx for your great help,,i understand the concept finally
Leave a comment