Skip to content

Instantly share code, notes, and snippets.

@halilozel1903
Created March 25, 2023 21:14
Show Gist options
  • Save halilozel1903/6bf5a540e928d3559b83bf97c405a07a to your computer and use it in GitHub Desktop.
Save halilozel1903/6bf5a540e928d3559b83bf97c405a07a to your computer and use it in GitHub Desktop.
fun main() {
val limit = 20
print("Prime numbers up to $limit: ")
for (i in 2..limit) {
if (isPrime(i)) {
print("$i ")
}
}
}
fun isPrime(number: Int): Boolean {
if (number <= 1) {
return false
}
for (i in 2 until number) {
if (number % i == 0) {
return false
}
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment