What is the problem in this Fibonacci codes ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
11th Jun 2017, 10:17 AM
Siddharth Saraf
2 Answers
+ 10
Increments are invalid: // p+=f (1+1= p=2) & f+=p (1+2=3) My last fibonacci was 5 or 6 months ago, but this works pretty well btw, maybe there is a best solution, i'm too lazy in this moment sry. :3 // t is a "temporary" variable var p, f, i, t; i = 0; p = 1; f = 0; document.write(p + "<br />"); // 1 for (; i <= 10; i++) { t = p; p += f; f = t; document.write(p + "<br />"); }
11th Jun 2017, 10:38 AM
Maz
Maz - avatar
+ 5
Actually p is the previous number , f is the fibnocci number , i is for the loop 10 times
11th Jun 2017, 10:56 AM
Siddharth Saraf