Answer to Question #5193 in C++ for aswinrdev

Question #5193
A PROGRAM TO GENERATE FIBANOCCI UPTO A GIVEN NO 112358
1
Expert's answer
2011-11-18T09:04:11-0500
#include <iostream.h>
int fib(int n)
{
if((1 == n) || (2 == n)) return 1;
else return fib(n-1) + fib(n-2);
}
int main(){
int i, n;
cout<<"enter n:";
cin>>n;
for(i=1; i<=n; i++) cout << fib(i) << endl;
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

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS