Implement a recursive function which would calculate the sum of all numbers from 1 to a given number.
Recursion
Programming a recursive function: calculating the sum of numbers from 1 to n.
Report a typo
Sample Input 1:
7Sample Output 1:
28Write 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))
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.