“Nomor Fibonacci” Kode Jawaban

fibonacci

# Easy fibonacci exercise
# Method #1
def fibonacci(n):
    # 1th: 0
    # 2th: 1
    # 3th: 1 ...
    if n == 1:
        return 0
    elif n == 2:
        return 1
    else:
        return fibonacci(n - 1) + fibonacci(n - 2)

# Method #2
def fibonacci2(n):
    if n == 0: return 0
    n1 = 1
    n2 = 1
    # (1, n - 2) because start by 1, 2, 3... not 0, 1, 1, 2, 3....
    for i in range(1, n - 2):
        n1 += n2
        n2 = n1 - n2
    return n1


print(fibonacci(13))
# return the nth element in the fibonacci sequence
Solo developer

100 angka fibonacci pertama

#for loop
fibonacci = [0,1]

for i in range(98):
    i=fibonacci.append(fibonacci[-1]+fibonacci[-2])
    
print(fibonacci)
Ferry_Morris

Nomor Fibonacci

function Fibonacci(num){
	        var before = 0;
	        var actual = 1;
	        var next = 1;

	        for(let i = 0; i < num; i++){
		        console.log(next)
		        before = actual + next;
		        actual = next
		        next = before
	        }
        }

        Fibonacci(100);
Clean Crocodile

Fibonacci ke -10

assert(fib(10) == 55)
Stormy Salmon

Nomor Fibonacci

f(n) = f(n-1) + f(n-2) 
                                  f(6)
                                   ^
  			                       /\
                f(5)               +                       f(4)
                ^
               /\                                           /\
                
        f(4)    +           f(3)                     f(3)    +    f(2)
       ^                       ^                     ^              ^
      /\                       /\                    /\            /\
   
 f(3)   +       f(2)            f(2) +f(1)       f(2) + f(1)   f(1) +  f(0)             
   ^              ^                ^                ^
   /\             /\                /\              /\
    
f(2) + f(1)      f(1) +  f(0)     f(1)+ f(0)       f(1) + f(0)         
  ^
  /\
f(1) +  f(0) 
  
//f(6) = 8   ==>  f(1)*8    f(1) appears 8 times 
 double 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));  
  
f(1) == 1;   
  
  
  
  
  
  
  
Mero

Jawaban yang mirip dengan “Nomor Fibonacci”

Pertanyaan yang mirip dengan “Nomor Fibonacci”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya