
Practice 50 Kotlin Recursion Function Coding Questions
Q1. Write a Kotlin program to find the factorial of a number using recursion.
Input: num = 5
Expected Output: 120
Q2. Write a Kotlin program to print the Fibonacci sequence up to a given number using recursion.
Input: num = 5
Expected Output: 0 1 1 2 3
Q3. Write a Kotlin program to calculate the power of a number using recursion.
Input: base = 2, exponent = 3
Expected Output: 8
Q4. Write a Kotlin program to check if a number is prime using recursion.
Input: num = 11
Expected Output: Prime
Q5. Write a Kotlin program to find the sum of digits of a number using recursion.
Input: num = 123
Expected Output: 6
Q6. Write a Kotlin program to find the nth Fibonacci number using recursion.
Input: n = 4
Expected Output: 3
Q7. Write a Kotlin program to reverse a string using recursion.
Input: str = "Kotlin"
Expected Output: "niltoK"
Q8. Write a Kotlin program to find the greatest common divisor (GCD) of two numbers using recursion.
Input: a = 56, b = 98
Expected Output: 14
Q9. Write a Kotlin program to calculate the sum of an array using recursion.
Input: arr = [1, 2, 3, 4]
Expected Output: 10
Q10. Write a Kotlin program to find the length of a string using recursion.
Input: str = "Kotlin"
Expected Output: 6
Q11. Write a Kotlin program to calculate the factorial of a number using recursion with a helper function.
Input: num = 4
Expected Output: 24
Q12. Write a Kotlin program to print numbers from 1 to N using recursion.
Input: num = 5
Expected Output: 1 2 3 4 5
Q13. Write a Kotlin program to print numbers from N to 1 using recursion.
Input: num = 5
Expected Output: 5 4 3 2 1
Q14. Write a Kotlin program to find the sum of all elements in a list using recursion.
Input: list = [1, 2, 3, 4]
Expected Output: 10
Q15. Write a Kotlin program to print a string in reverse order using recursion.
Input: str = "Hello"
Expected Output: "olleH"
Q16. Write a Kotlin program to find the nth power of a number using recursion.
Input: base = 3, n = 2
Expected Output: 9
Q17. Write a Kotlin program to count the occurrences of a character in a string using recursion.
Input: str = "Kotlin", char = 't'
Expected Output: 1
Q18. Write a Kotlin program to calculate the sum of even numbers from 1 to N using recursion.
Input: num = 6
Expected Output: 12
Q19. Write a Kotlin program to calculate the sum of odd numbers from 1 to N using recursion.
Input: num = 5
Expected Output: 9
Q20. Write a Kotlin program to print a triangular pattern of stars using recursion.
Input: n = 3
Expected Output:
*
**
***
Q21. Write a Kotlin program to check if a number is a palindrome using recursion.
Input: num = 121
Expected Output: Palindrome
Q22. Write a Kotlin program to find the maximum number in an array using recursion.
Input: arr = [1, 2, 3, 4]
Expected Output: 4
Q23. Write a Kotlin program to find the minimum number in an array using recursion.
Input: arr = [5, 1, 8, 3]
Expected Output: 1
Q24. Write a Kotlin program to find the sum of squares of numbers from 1 to N using recursion.
Input: num = 3
Expected Output: 14
Q25. Write a Kotlin program to find the number of digits in a number using recursion.
Input: num = 12345
Expected Output: 5
Q26. Write a Kotlin program to find the sum of numbers from 1 to N using recursion.
Input: num = 4
Expected Output: 10
Q27. Write a Kotlin program to reverse the elements of an array using recursion.
Input: arr = [1, 2, 3, 4]
Expected Output: [4, 3, 2, 1]
Q28. Write a Kotlin program to print the multiplication table of a number using recursion.
Input: num = 3
Expected Output:
3 x 1 = 3
3 x 2 = 6
3 x 3 = 9
Q29. Write a Kotlin program to find the sum of an array using recursion with a helper function.
Input: arr = [1, 2, 3, 4]
Expected Output: 10
Q30. Write a Kotlin program to find the first N natural numbers using recursion.
Input: n = 5
Expected Output: 1 2 3 4 5
Q31. Write a Kotlin program to calculate the reverse of a number using recursion.
Input: num = 123
Expected Output: 321
Q32. Write a Kotlin program to find the greatest common divisor (GCD) of two numbers using recursion.
Input: a = 56, b = 98
Expected Output: 14
Q33. Write a Kotlin program to calculate the sum of even numbers in an array using recursion.
Input: arr = [1, 2, 3, 4, 5]
Expected Output: 6
Q34. Write a Kotlin program to find the factorial of a number using recursion with base case handling.
Input: num = 6
Expected Output: 720
Q35. Write a Kotlin program to print all the factors of a number using recursion.
Input: num = 12
Expected Output: 1 2 3 4 6 12
Q36. Write a Kotlin program to check if a string is a palindrome using recursion.
Input: str = "madam"
Expected Output: Palindrome
Q37. Write a Kotlin program to print a pyramid pattern of stars using recursion.
Input: n = 3
Expected Output:
*
***
*****
Q38. Write a Kotlin program to check if a number is even or odd using recursion.
Input: num = 7
Expected Output: Odd
Q39. Write a Kotlin program to find the sum of an array of integers using recursion.
Input: arr = [5, 10, 15]
Expected Output: 30
Q40. Write a Kotlin program to find the index of a given element in an array using recursion.
Input: arr = [1, 2, 3, 4], element = 3
Expected Output: 2
Q41. Write a Kotlin program to calculate the number of vowels in a string using recursion.
Input: str = "Kotlin"
Expected Output: 2
Q42. Write a Kotlin program to find the highest power of 2 less than or equal to a number using recursion.
Input: num = 15
Expected Output: 8
Q43. Write a Kotlin program to check if a number is an Armstrong number using recursion.
Input: num = 153
Expected Output: Armstrong number
Q44. Write a Kotlin program to find the sum of elements in a nested array using recursion.
Input: arr = [[1, 2], [3, 4]]
Expected Output: 10
Q45. Write a Kotlin program to calculate the total number of elements in an array using recursion.
Input: arr = [1, 2, 3]
Expected Output: 3
Q46. Write a Kotlin program to calculate the product of digits of a number using recursion.
Input: num = 123
Expected Output: 6
Q47. Write a Kotlin program to find the smallest number in an array using recursion.
Input: arr = [10, 20, 5]
Expected Output: 5
Q48. Write a Kotlin program to calculate the sum of elements at even indices in an array using recursion.
Input: arr = [1, 2, 3, 4]
Expected Output: 4
Q49. Write a Kotlin program to find the factorial of a number using recursion with base case 1.
Input: num = 5
Expected Output: 120
Q50. Write a Kotlin program to find the sum of an array of odd numbers using recursion.
Input: arr = [1, 3, 5]
Expected Output: 9