Skip to content

Instantly share code, notes, and snippets.

@Nadeeshyama
Last active January 24, 2021 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nadeeshyama/4e5b4d11306eab50d6c1 to your computer and use it in GitHub Desktop.
Save Nadeeshyama/4e5b4d11306eab50d6c1 to your computer and use it in GitHub Desktop.
[Fibonacci Sequence] JavaScript function to output first 40 Fibonacci numbers that converge to Pi #Console
/**
* JavaScript function to output first 40 Fibonacci and convergence to Pi
*/
for (var p = 1, q = 1, t, i = 1; i < 41; i++) {
console.log('Fibonacci[%d] (%d + %d): %d; Pi: %f', i, p, q, q, (q/p));
t = q;
q = p + q;
p = t;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment