Leap Year
Applies the calendar rules to tell whether a year is a leap year.
- Level
- Intermediate
- Topic:
- Decisions
- Concepts:
- Input & output
- Si
- Colloquial conditions
Open in Codoritmo
Run, change and debug this example in your browser.
What you'll learn
Es Multiplo De is a colloquial condition, a more readable way to write MOD = 0. The order of the nested Si blocks matters: 400 first, then 100, then 4.
Code
Algoritmo AnioBisiesto Definir anio Como Entero Escribir "Escribe un año:" Leer anio // "Es Multiplo De" es una condición coloquial de PSeInt Si anio Es Multiplo De 400 Entonces Escribir anio, " es bisiesto." SiNo Si anio Es Multiplo De 100 Entonces Escribir anio, " no es bisiesto (es múltiplo de 100 pero no de 400)." SiNo Si anio Es Multiplo De 4 Entonces Escribir anio, " es bisiesto: febrero tiene 29 días." SiNo Escribir anio, " no es bisiesto." FinSi FinSi FinSiFinAlgoritmoFlowchart
Each block in the flowchart matches one instruction in the code.
Sample run
This is what the program shows when it runs. The answers typed by the user are highlighted.
Escribe un año:User answer: 20242024 es bisiesto: febrero tiene 29 días.
Challenge
Ask for a start and an end year, and list every leap year in between.
Show hint
Wrap the decision in a Para loop that walks through the years in the range.
Related examples
Body Mass Index
Computes your BMI and classifies it as underweight, normal and so on.
IntermediateCan I Vote?
Tells you whether you can vote or how many years you have left.
BeginnerGuess the Number
Guess a secret number from 1 to 100 in seven tries.
Intermediate