C Program to Check Leap Year

This program checks whether a given year is a leap year or not based on the rules of the Gregorian calendar.

Concept Overview

A year is a leap year if it is divisible by 4. However, if the year is also divisible by 100, it must also be divisible by 400 to be a leap year. For example, 2000 and 2024 are leap years, while 1900 and 2023 are not.

Program

C
#include <stdio.h>

int main() {
    int year;

    printf("Enter a year: ");
    scanf("%d", &year);

    if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
        printf("%d is a leap year.\n", year);
    else
        printf("%d is not a leap year.\n", year);

    return 0;
}

Sample Output

Enter a year: 2024
2024 is a leap year.

Explanation

  • The program takes the year as input from the user.
  • It checks if the year is divisible by 400, or divisible by 4 but not by 100.
  • If either condition is true, it prints that the year is a leap year; otherwise, it is not.
  • The logic follows the standard leap year rule of the Gregorian calendar.
Note: Note: Leap years occur every 4 years, except for century years not divisible by 400.