Programming a recursive function: calculating the sum of numbers from 1 to n.

Report a typo

Implement a recursive function which would calculate the sum of all numbers from 1 to a given number.

Sample Input 1:

7

Sample Output 1:

28
Write a program in Kotlin
fun sumRecursive(n: Int): Int {
// base case / terminal condition here
// recursive call here
}

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

Create a free account to access the full topic