# Kotlin Program to Check Whether a Number can be Expressed as Sum of Two Prime Numbers

Kotlin Program to Check Whether a Number can be Expressed as Sum of Two Prime Numbers: In this program, you’ll learn to check whether a given number can be expressed as a sum of two prime numbers or not. This is done with the help of loops and break statements in Kotlin.

## Kotlin Program to Check Whether a Number can be Expressed as Sum of Two Prime Numbers

Source Code

``````fun main(args: Array<String>) {
val number = 34
var flag = false
for (i in 2..number / 2) {

// condition for i to be a prime number
if (checkPrime(i)) {

// condition for n-i to be a prime number
if (checkPrime(number - i)) {

System.out.printf("%d = %d + %d\n", number, i, number - i)
flag = true
}

}
}

if (!flag)
println("\$number cannot be expressed as the sum of two prime numbers.")
}

// Function to check prime number
fun checkPrime(num: Int): Boolean {
var isPrime = true

for (i in 2..num / 2) {
if (num % i == 0) {
isPrime = false
break
}
}

return isPrime
}``````

Output