Skip to content
Exercise · Conditions · lesson 5 of 6

Exercise: leap year

Write a function bool is_leap(int year) that returns true if the year is a leap year and false otherwise. A leap year is divisible by 4, but of the years divisible by 100, only those divisible by 400 are leap years.

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

Constraints: year is from 1 to 9999.

leap.cpp — cpp
cpp · 4 lines
Ctrl+Enter run · Esc leave editor