Skip to content

Instantly share code, notes, and snippets.

@ikhsanalatsary
Last active August 13, 2018 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikhsanalatsary/9cc0a89b6b3deb0b9f37571201f841f7 to your computer and use it in GitHub Desktop.
Save ikhsanalatsary/9cc0a89b6b3deb0b9f37571201f841f7 to your computer and use it in GitHub Desktop.
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