1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
function fib(n) { let a = 0, b = 1, c, i; if( n == 0) return a; for(i = 2; i <= n; i++) { c = a + b; a = b; b = c; } return b; } // Driver code let n = 25; document.write(fib(n)); // This code is contributed by Mayank Tyagi, From geeksforgeeks.org