Practice 50 Kotlin Control Flow Coding Questions , TechnoVlogs

Practice 50 Kotlin Control Flow Coding Questions


Q1. Write a Kotlin program to check if a number is positive, negative, or zero using an if-else statement.
  Input: num = 7
  Expected Output: Positive

Q2. Write a Kotlin program to check if a number is even or odd using an if-else statement.
  Input: num = 8
  Expected Output: Even

Q3. Write a Kotlin program to check if a number is divisible by 3 using the if-else statement.
  Input: num = 9
  Expected Output: Divisible by 3

Q4. Write a Kotlin program to find the largest of three numbers using the if-else statement.
  Input: a = 10, b = 20, c = 15
  Expected Output: Largest number is: 20

Q5. Write a Kotlin program to check if a number is divisible by both 5 and 7.
  Input: num = 35
  Expected Output: Divisible by both 5 and 7

Q6. Write a Kotlin program to print the grade of a student based on the marks using the if-else-if statement.
  Input: marks = 85
  Expected Output: Grade: A

Q7. Write a Kotlin program to determine if a number is prime using an if-else statement.
  Input: num = 11
  Expected Output: Prime

Q8. Write a Kotlin program to find the smallest of three numbers using the if-else statement.
  Input: a = 7, b = 12, c = 9
  Expected Output: Smallest number is: 7

Q9. Write a Kotlin program to check if a number is a leap year using an if-else statement.
  Input: year = 2020
  Expected Output: Leap year

Q10. Write a Kotlin program to find the factorial of a number using a for loop.
   Input: num = 5
   Expected Output: Factorial is: 120

Q11. Write a Kotlin program to print the Fibonacci sequence up to a given number using a for loop.
   Input: num = 8
   Expected Output: 0 1 1 2 3 5 8

Q12. Write a Kotlin program to find the sum of all even numbers in an array using a for loop.
   Input: arr = [1, 2, 3, 4, 5, 6]
   Expected Output: Sum of even numbers is: 12

Q13. Write a Kotlin program to check if a number is a perfect number using a for loop.
   Input: num = 28
   Expected Output: Perfect number

Q14. Write a Kotlin program to print the multiplication table of a given number using a for loop.
   Input: num = 5
   Expected Output:     
     5 x 1 = 5
     5 x 2 = 10
     5 x 3 = 15

Q15. Write a Kotlin program to calculate the sum of all odd numbers in an array using a for loop.
   Input: arr = [1, 2, 3, 4, 5]
   Expected Output: Sum of odd numbers is: 9

Q16. Write a Kotlin program to count the number of vowels in a string using a for loop.
   Input: str = "Kotlin"
   Expected Output: Vowel count is: 2

Q17. Write a Kotlin program to find the largest number in an array using a for loop.
   Input: arr = [2, 5, 3, 9, 1]
   Expected Output: Largest number is: 9

Q18. Write a Kotlin program to check if a string contains the letter 'a' using an if-else statement.
   Input: str = "Kotlin"
   Expected Output: Contains 'a'

Q19. Write a Kotlin program to calculate the sum of digits of a number using a while loop.
   Input: num = 123
   Expected Output: Sum of digits is: 6

Q20. Write a Kotlin program to reverse a string using a while loop.
   Input: str = "Kotlin"
   Expected Output: niltoK

Q21. Write a Kotlin program to print the prime numbers from 1 to N using a while loop.
   Input: N = 10
   Expected Output: 2 3 5 7

Q22. Write a Kotlin program to check if a number is divisible by 5 or 7 using a while loop.
   Input: num = 35
   Expected Output: Divisible by 5 or 7

Q23. Write a Kotlin program to print the first N natural numbers using a while loop.
   Input: N = 5
   Expected Output: 1 2 3 4 5

Q24. Write a Kotlin program to print the first N odd numbers using a while loop.
   Input: N = 5
   Expected Output: 1 3 5 7 9

Q25. Write a Kotlin program to print a pattern using a for loop.
   Input: n = 3
   Expected Output:
     *
     **
     ***

Q26. Write a Kotlin program to check if a number is divisible by 3 or 5 using the when expression.
   Input: num = 15
   Expected Output: Divisible by 3 or 5

Q27. Write a Kotlin program to check the day of the week using a when expression.
   Input: day = 3
   Expected Output: Wednesday

Q28. Write a Kotlin program to check the season based on the month using a when expression.
   Input: month = 6
   Expected Output: Summer

Q29. Write a Kotlin program to check the grade based on the marks using the when expression.
   Input: marks = 75
   Expected Output: Grade: B

Q30. Write a Kotlin program to print the name of a color based on its code using the when expression.
   Input: code = 1
   Expected Output: Red

Q31. Write a Kotlin program to find the number of days in a month using the when expression.
   Input: month = 2
   Expected Output: 28 days

Q32. Write a Kotlin program to check if a character is a vowel or consonant using the when expression.
   Input: char = 'a'
   Expected Output: Vowel

Q33. Write a Kotlin program to print the first N even numbers using a for loop.
   Input: N = 4
   Expected Output: 2 4 6 8

Q34. Write a Kotlin program to print a pyramid pattern using a for loop.
   Input: n = 4
   Expected Output:
       *
      ***
     *****
    *******      

Q35. Write a Kotlin program to print the sum of elements in an array using a for loop.
   Input: arr = [1, 2, 3, 4]
   Expected Output: Sum is: 10

Q36. Write a Kotlin program to check if a string starts with a specific character using the when expression.
   Input: str = "Kotlin", char = 'K'
   Expected Output: Starts with 'K'

Q37. Write a Kotlin program to check if a string ends with a specific character using the when expression.
   Input: str = "Kotlin", char = 'n'
   Expected Output: Ends with 'n'

Q38. Write a Kotlin program to print the factorial of a number using a while loop.
   Input: num = 4
   Expected Output: Factorial is: 24

Q39. Write a Kotlin program to print a reverse triangle pattern using a for loop.
   Input: n = 5
   Expected Output:
     *****
     ****
     ***
     **
     *      

Q40. Write a Kotlin program to check if a number is a palindrome using an if-else statement.
   Input: num = 121
   Expected Output: Palindrome

Q41. Write a Kotlin program to find the GCD of two numbers using a while loop.
   Input: a = 56, b = 98
   Expected Output: GCD is: 14

Q42. Write a Kotlin program to check if a number is an Armstrong number using an if-else statement.
   Input: num = 153
   Expected Output: Armstrong number

Q43. Write a Kotlin program to check if a number is a perfect square using an if-else statement.
   Input: num = 16
   Expected Output: Perfect square

Q44. Write a Kotlin program to find the sum of diagonal elements in a matrix using a for loop.
   Input: matrix = [[1, 2], [3, 4]]
   Expected Output: Sum of diagonal elements is: 5

Q45. Write a Kotlin program to print all odd numbers between two given numbers using a for loop.
   Input: start = 1, end = 10
   Expected Output: 1 3 5 7 9

Q46. Write a Kotlin program to find the second largest number in an array using a for loop.
   Input: arr = [4, 6, 9, 1]
   Expected Output: Second largest number is: 6

Q47. Write a Kotlin program to calculate the sum of elements in a list using a for loop.
   Input: list = [1, 2, 3, 4]
   Expected Output: Sum is: 10

Q48. Write a Kotlin program to count the number of occurrences of a character in a string using a for loop.
   Input: str = "Kotlin", char = 'o'
   Expected Output: Occurrences: 1

Q49. Write a Kotlin program to create a multiplication table of a number using a for loop.
   Input: num = 7
   Expected Output:     
     7 x 1 = 7
     7 x 2 = 14
     7 x 3 = 21

Q50. Write a Kotlin program to print all the even numbers from 1 to N using a for loop.
   Input: N = 10
   Expected Output: 2 4 6 8 10

Share on Social Media