forked from kelvins/algorithms-and-data-structures
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFibonacci.kt
24 lines (23 loc) · 1020 Bytes
/
Fibonacci.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
* "fibonacciRecursive" function
*
* The *fibonacciRecursive* function displays the values of the Fibonacci sequence in which, the first two terms of this sequence are less than or equal to 1, and each term that follows next will be the sum of the two previous numbers (0, 1, 1, 2, 3, 5, 8...).
* In this function, the concept of *recursion* is used, in which the created function is called within it, one or more times internally.
*
* @author Algorithm version for Kotlin: Alfredo Paes <alfredo.alfpaes@gmail.com>
* @see https://github.com/Alfredo-Paes
*
* @param number is of type integer (Int)
*
* @return will return a logical condition if *number* is less than or equal to 1, returns 1 otherwise, the sum of itself using the concept of *recursion* to execute this sum.
*/
fun fibonacciRecursive(number: Int): Int {
return if (number <= 1) {
1
}; else {
fibonacciRecursive(number - 1) + fibonacciRecursive(number - 2)
}
}
fun main() {
println(fibonacciRecursive(5))
}