Computer Science – 9.2 Algorithms | e-Consult
9.2 Algorithms (1 questions)
Login to see all questions.
Click on a question to view the answer
Algorithm:
- Input: Year (e.g., 2024)
- Check if Year is divisible by 4:
- If No: Not a leap year
- Else if Year is divisible by 100:
- Check if Year is divisible by 400:
- If Yes: Leap year
- If No: Not a leap year
- Check if Year is divisible by 400:
- Else if Year is divisible by 4 and not by 100:
- If Yes: Leap year
- Output: Leap Year (True/False)
Pseudocode:
IF Year MOD 4 = 0 THEN
IF Year MOD 100 = 0 THEN
IF Year MOD 400 = 0 THEN
LeapYear = TRUE
ELSE
LeapYear = FALSE
ENDIF
ELSE
LeapYear = TRUE
ENDIF
ELSE
LeapYear = FALSE
ENDIF