+ 2

Is it possible to make a program which prints the fibonachi series with only two variables.

23rd Jun 2017, 7:58 AM
ART
ART - avatar
2 Réponses
+ 4
#include<iostream> int fibo ( int index ) { if(index == 0) return 0; else if(index == 1) return 1; else return fibo(n-1)+fibo(n-2); } //No of variables used till now - 1 int main() { cout<<"Fibonacci Series - "<<endl<<endl; for(int i=0;i<600;i++) cout<<fibo(i)<<endl; } //No of variables used till now - 2 //3rd one can be the limit till which you want the series to be printed. And one will have to input it...
23rd Jun 2017, 8:29 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 1
@kinshuk Thanks man, amazing logic. Didn't think it could be done through recursion.
23rd Jun 2017, 2:27 PM
ART
ART - avatar