vendredi 29 septembre 2017

Fibonacci Series Using One variable

I digged in StackOverflow for about 10 minutes but I found no other question related this.
Problem: I am trying to print the fibonacci using one variable,

Tried: I am little bit confused as I use recursion :
I have to print the value when I reach the minimal value thats if var = 0 return 0; in upwards direction thats 0,1,1,2,3,5,7 ... plus at that time I have to return that value.
I can do something (Algorithm):

var = fab( n- 1 ) + fab(n-2)
Print var
Return var

But I have only to use one variable.

Aucun commentaire:

Enregistrer un commentaire