0

Can anyone tell the code to print the Fibonacci series ?

24th Oct 2015, 6:45 PM
Varun Subramanian
Varun Subramanian - avatar
2 Respuestas
+ 4
int main() { int a=0,b=1,i,j, c; cout<<"enter terms"; cin>>i; cout<<a<<"\t"<<b<<"\t"; for(j=0;j<i-2;j++) { c=a+b; a=b; b=c; cout<<c<<"\t"; } return 0; }
6th Dec 2015, 7:55 PM
Saurabh Swaraj
Saurabh Swaraj - avatar
0
Using recursion: #include <iostream> using namespace std; int fibonacci(int n) { if((n==1)||(n==0)) return(n); else return(fibonacci(n-1)+fibonacci(n-2)); } int main() { int n; cin >> n; for(int i = 0;i < n;++i) cout << fibonacci(i) << endl; return 0; }
22nd Mar 2017, 2:36 PM
Onik Babajanyan
Onik Babajanyan - avatar