We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 513070d commit e8718e1Copy full SHA for e8718e1
src/swift/fibonacciRecursive.swift
@@ -0,0 +1,12 @@
1
+// Function to calculate Fibonacci numbers recursively
2
+func fibonacciRecursive(_ number: Int) -> Int {
3
+ if number <= 1 {
4
+ return number
5
+ } else {
6
+ // Recursively calculate Fibonacci using the formula F(n) = F(n-1) + F(n-2)
7
+ return fibonacciRecursive(number - 1) + fibonacciRecursive(number - 2)
8
+ }
9
+}
10
+
11
+let index: Int = 15
12
+print("Fibonacci (recursive):", fibonacciRecursive(index))
0 commit comments