Last active
August 13, 2018 06:18
-
-
Save ikhsanalatsary/9cc0a89b6b3deb0b9f37571201f841f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
func fibonacci (until n: Int) -> [Int] { | |
var num1 = 0 | |
var num2 = 1 | |
var fibonacciNumber = [Int]() | |
for _ in 0...n { | |
let temp = num1 | |
num1 = num1 + num2 | |
num2 = temp | |
fibonacciNumber.append(num2) | |
} | |
return fibonacciNumber | |
} | |
print(fibonacci(until: 7)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment