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.
2. Write a Kotlin recursive function to calculate the power of a number.
3. Write a Kotlin recursive function to calculate the sum of elements in an array.
4. Write a Kotlin recursive function to find the smallest element in an array.
5. Write a Kotlin recursive function to generate all permutations of a given string.
6. Write a Kotlin recursive function to calculate the product of all odd numbers in a range.
7. Write a Kotlin recursive function to find the nth term of the arithmetic sequence.
8. Write a Kotlin recursive function to check if a number is a prime number.
9. Write a Kotlin recursive function to calculate the sum of all digits in a string.
10. Write a Kotlin recursive function to calculate the sum of the even Fibonacci numbers up to a given limit.
11. Write a Kotlin recursive function to find the maximum depth of a binary tree.
12. Write a Kotlin recursive function to check if a binary tree is a binary search tree.
13. Write a Kotlin recursive function to calculate the sum of all even numbers in a range.
14. Write a Kotlin tail recursive function that calculates the factorial of a given number.
15. Write a Kotlin tail-recursive function to calculate the sum of all numbers from 1 to n.
16. Write a Kotlin tail-recursive function to calculate the nth Fibonacci number.
17. Write a Kotlin tail-recursive function to calculate the power of a number.
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.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/kotlin-exercises/recursion-function/index.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics