# Kotlin Recursion: Exercises, Practice, Solutions

## Kotlin Recursion and Tail Recursion function Exercises [ 17 exercises with solution ]

[An editor is available at the bottom of the page to write and execute the scripts.  Go to the editor]

1. Write a Kotlin recursive function to calculate the sum of the digits of a positive integer.

Click me to see the solution

2. Write a Kotlin recursive function to calculate the power of a number.

Click me to see the solution

3. Write a Kotlin recursive function to calculate the sum of elements in an array.

Click me to see the solution

4. Write a Kotlin recursive function to find the smallest element in an array.

Click me to see the solution

5. Write a Kotlin recursive function to generate all permutations of a given string.

Click me to see the solution

6. Write a Kotlin recursive function to calculate the product of all odd numbers in a range.

Click me to see the solution

7. Write a Kotlin recursive function to find the nth term of the arithmetic sequence.

Click me to see the solution

8. Write a Kotlin recursive function to check if a number is a prime number.

Click me to see the solution

9. Write a Kotlin recursive function to calculate the sum of all digits in a string.

Click me to see the solution

10. Write a Kotlin recursive function to calculate the sum of the even Fibonacci numbers up to a given limit.

Click me to see the solution

11. Write a Kotlin recursive function to find the maximum depth of a binary tree.

Click me to see the solution

12. Write a Kotlin recursive function to check if a binary tree is a binary search tree.

Click me to see the solution

13. Write a Kotlin recursive function to calculate the sum of all even numbers in a range.

Click me to see the solution

14. Write a Kotlin tail recursive function that calculates the factorial of a given number.

Click me to see the solution

15. Write a Kotlin tail-recursive function to calculate the sum of all numbers from 1 to n.

Click me to see the solution

16. Write a Kotlin tail-recursive function to calculate the nth Fibonacci number.

Click me to see the solution

17. Write a Kotlin tail-recursive function to calculate the power of a number.

Click me to see the solution

More to Come !

* To run the code mouse over on Result panel and click on 'RERUN' button.*

Kotlin Editor:

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.

﻿

Follow us on Facebook and Twitter for latest update.