forked from kelvins/algorithms-and-data-structures
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExponentiationRecursive.kt
More file actions
25 lines (24 loc) · 879 Bytes
/
ExponentiationRecursive.kt
File metadata and controls
25 lines (24 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
* "exponentiationRecursive" function
*
* The *exponentiationRecursive* function presents the values of a number (*base*) raised by an *exponent*.
* In this function, the concept of *recursion* is used, in which the created function is called within it, one or more times internally of the same.
*
* @author Algorithm version for Kotlin: Alfredo Paes <alfredo.alfpaes@gmail.com>
* @see https://github.com/Alfredo-Paes
*
* @param base is of type integer (Int)
* @param exponent is of type integer (Int)
*
* @return will return the *base* number raised by the *exponent*. The function returns a value of type *Long*.
*/
fun exponentiationRecursive(base: Int, exponent: Int): Long {
return if (exponent === 0) {
1
}; else {
base * exponentiationRecursive(base, exponent - 1)
}
}
fun main() {
println(exponentiationRecursive(2, 3))
}