Programming a recursive function.

Report a typo

Implement a recursive function F with the following rules:

f(n) = f(n-1)/2 + 2*f(n-2)

f(0) = 4

f(-1) = 1

The function needs to return the result of the calculation.

Sample Input 1:

5

Sample Output 1:

39
Write a program in Kotlin
fun f(n: Int): Int {
// your code here
}

fun main() {
val n = readLine()!!.toInt()
print(f(n))
}
___

Create a free account to access the full topic