Skip to content

Commit

Permalink
Merge pull request #6706 from iRetr0o/main
Browse files Browse the repository at this point in the history
Reto #4 - Kotlin
  • Loading branch information
Roswell468 authored Dec 18, 2024
2 parents 5ffbb21 + a1a9f2a commit 7105882
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Retos/Reto #4 - PRIMO, FIBONACCI Y PAR [Media]/kotlin/iRetr0o.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
fun main() {
checkNumber(3)
checkNumber(7)
}

fun isPrime(n: Int): Boolean {
if (n < 2) return false
for (i in 2 ..< n) {
if (n % i == 0) return false
}
return true
}

fun isFibonacci(n: Int): Boolean {
var a = 0
var b = 1
while (a < n) {
val temp = a
a = b
b += temp
}
return a == n
}

fun isEven(n: Int): Boolean {
return n % 2 == 0
}

fun checkNumber(n: Int) {
val prime = if (isPrime(n)) "primo" else "no es primo"
val fibonacci = if (isFibonacci(n)) "fibonacci" else "no es fibonacci"
val even = if (isEven(n)) "par" else "impar"
println("$n es $prime, $fibonacci y es $even")
}

0 comments on commit 7105882

Please sign in to comment.