Published on 11 October 2020 (Updated: 11 October 2020)

Welcome to the Fibonacci in Swift page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

importFoundationfuncfibonacciProgram(_n:Int){varf1=0,f2=1,fib=1foriin0..<n{print("\(i+1): \(fib)")fib=f1+f2f1=f2f2=fib}}funcfibonacciRecursive(_n:Int)->Int{if(n==0){return0}elseif(n==1){return1}returnfibonacciRecursive(n-1)+fibonacciRecursive(n-2)}/*
Check if there is exactly one argument and if it can be parsed as an integer
*/guardCommandLine.argc==2,letnumber=Int(CommandLine.arguments[1])else{print("Usage: please input the count of fibonacci numbers to output")exit(0)}fibonacciProgram(number)