1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| fun isPrime(n: Int): Boolean { if (n <= 1) return false for (i in 2 until n) { if (n % i == 0) { return false } } return true }
fun countPrimesInArray(arr: IntArray): Int { var count = 0 for (num in arr) { if (isPrime(num)) { count++ } } return count }
fun main() { val arr = intArrayOf(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15) println("Count of prime numbers in the array: ${countPrimesInArray(arr)}") }
|