C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

Decision Making Programs in C

Check whether a year is a Leap Year

Introduction

A leap year has 366 days instead of 365, with February 29 as the extra day.

Rules to check a leap year:

  1. If a year is divisible by 4 → it might be a leap year
  2. If the year is divisible by 100 → it is not a leap year, unless
  3. The year is also divisible by 400 → it is a leap year

Examples:

  • 2020 → Leap Year (divisible by 4, not by 100)
  • 1900 → Not a Leap Year (divisible by 100, not by 400)
  • 2000 → Leap Year (divisible by 400)

 

C Program: Check whether a year is a Leap Year

C

#include <stdio.h>

 

int main() {

    int year;

 

    // Input year from user

    printf("Enter a year: ");

    scanf("%d", &year);

 

    // Check leap year conditions

    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;

}

Output

 
OUTPUT 1 :
Enter a year: 2024
2024 is a Leap Year.

OUTPUT 2 :
Enter a year: 1900
1900 is not a Leap Year.


OUTPUT 3 :
Enter a year: 2000
2000 is a Leap Year.
 

Explanation

  1. User enters a year.
  2. Condition checks:
    • (year % 4 == 0 && year % 100 != 0) → divisible by 4 but not by 100
    • (year % 400 == 0) → divisible by 400
  3. If either condition is true → Leap Year
  4. Else → Not a Leap Year