Published on 28 April 2022 (Updated: 18 September 2022)

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)