Skip to content
Exercise · Operators · lesson 8 of 9

Exercise: leap year

Write a function func isLeap(year int) bool that returns true if the year is a leap year. A year is a leap year when it is divisible by 4 but not by 100. Years divisible by 400 are the exception: they are leap years.

  • isLeap(2024) → true
  • isLeap(1900) → false
  • isLeap(2000) → true

Constraints: year is an integer from 1 to 9999.

Do not add extra imports unless the task says so explicitly.

leap.go — go
go · 6 lines
Ctrl+Enter run · Esc leave editor

Subscribe to take the course

The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.

Sign in another way