1# Program to display the Fibonacci sequence up to n-th term
2
3nterms = int(input("How many terms? "))
4
5# first two terms
6n1, n2 = 0, 1
7count = 0
8
9# check if the number of terms is valid
10if nterms <= 0:
11 print("Please enter a positive integer")
12elif nterms == 1:
13 print("Fibonacci sequence upto",nterms,":")
14 print(n1)
15else:
16 print("Fibonacci sequence:")
17 while count < nterms:
18 print(n1)
19 nth = n1 + n2
20 # update values
21 n1 = n2
22 n2 = nth
23 count += 1
1function myFib(n) {
2 if (isNaN(n) || Math.floor(n) !== n)
3 return "Not an integer value!";
4 if (n === 0 || n === 1)
5 return 3;
6 else
7 return myFib(n - 1) + myFib(n - 2);
8}
9
10console.log(myFib(5));
11
12
13
1// Copy paste code here https://play.golang.org/
2package main
3
4import "fmt"
5
6func fibo(n int) int {
7 x, y := 0, 1
8 for i := 0; i < n; i++ {
9 x, y = y, x+y
10 }
11 return x
12}
13
14func main() { fmt.Println(fibo(5)) } // return 5
1//x is the index number in the fibonnacci sequence.
2//The function will return that index's fibonacci value
3function fib(x) {
4 let a = 0;
5 let b = 1;
6 for (var i = 0; i < x-1; i++) {
7 let c = b;
8 b += a;
9 a = c;
10 }
11 return b;
12}
1
2int n ;
3double feb = (1/Math.pow(5,0.5)) * (Math.pow((1+Math.pow(5,0.5))/2,n)) - (1/Math.pow(5,0.5))* (Math.pow((1-Math.pow(5,0.5))/2,n));