1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
fun main() { println("Números primos del 1 al 1000:") mostrarNumerosPrimos(1, 1000) println("\nAños bisiestos entre el año 2000 y el 3000:") mostrarAniosBisiestos(2000, 3000) } fun mostrarNumerosPrimos(inicio: Int, fin: Int) { for (numero in inicio..fin) { if (esPrimo(numero)) { print("$numero ") } } } fun esPrimo(numero: Int): Boolean { if (numero <= 1) { return false } for (i in 2 until numero) { if (numero % i == 0) { return false } } return true } fun mostrarAniosBisiestos(inicio: Int, fin: Int) { for (anio in inicio..fin) { if (esBisiesto(anio)) { print("$anio ") } } } fun esBisiesto(anio: Int): Boolean { return (anio % 4 == 0 && anio % 100 != 0) || (anio % 400 == 0) } |