P
P
Proshka172019-11-15 14:14:40
Swift
Proshka17, 2019-11-15 14:14:40

Swift Fibonacci what is wrong?

Good afternoon!
When you run this code, Terminated by signal 11 crashes, what's wrong?
PS just starting in SWIFT

import Foundation

func fibbonachi(_ n: Int...){

    if n.count==0 {
        print(1)
        fibbonachi(0,1)
    }
    else {
        if n[0]==144 {return;}
        print(n[0]+n[1])
        var left = n[0]
        fibbonachi(n[0],left+n[1])
    }
}
fibbonachi()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-11-15
@Proshka17

fibbonachi(n[0],left+n[1])

Yah? The first term of the next value must be the second term of the previous one:
fibbonachi(n[1], left + n[1])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question