Concepto general:
Un año bisiesto es aquel divisible entre 4, excepto los que son divisibles entre 100, a menos que también sean divisibles entre 400.
Pseudocódigo:
1. Pedir el año al usuario.
2. Si el año es divisible por 400 → Es bisiesto.
3. Sino, si el año es divisible por 100 → No es bisiesto.
4. Sino, si el año es divisible por 4 → Es bisiesto.
5. En cualquier otro caso → No es bisiesto.
<script>
function verificarBisiesto() {
let anio = parseInt(document.getElementById("anio").value);
let resultado = "";
if (anio % 400 == 0) {
resultado = anio + " es un año bisiesto";
} else if (anio % 100 == 0) {
resultado = anio + " NO es un año bisiesto";
} else if (anio % 4 == 0) {
resultado = anio + " es un año bisiesto";
} else {
resultado = anio + " NO es un año bisiesto";
}
<h3>Verifica si un año es bisiesto</h3>
<input type="number" id="anio" placeholder="Ingresa un año">
<button onclick="verificarBisiesto()">Verificar</button>
<p id="resultado5" style="font-weight: bold; color: blue;"></p>
</body>
</html>
No hay comentarios:
Publicar un comentario