+ 2
Is it possible to make a program which prints the fibonachi series with only two variables.
2 odpowiedzi
+ 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...
+ 1
@kinshuk Thanks man, amazing logic. Didn't think it could be done through recursion.