C Program to Check Leap Year

The distinction between a common year and a leap year is determined by the number of days in a year. Generally, a common year consists of 365 days, while a leap year consists of 366 days. The calculation method is as follows:

  1. A leap year is defined as a year that is divisible by 4 but not by 100.
  2. If the year is divisible by 400, it is also a leap year.
  3. In other cases, it’s an average year.

Here is a simple C language code example to determine whether a given year is a leap year or not.

#include <stdio.h>

int main() {
    int year;

    printf("请输入一个年份:");
    scanf("%d", &year);

    if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
        printf("%d年是闰年。\n", year);
    } else {
        printf("%d年是平年。\n", year);
    }

    return 0;
}

You can input a year in this sample code, and the program will determine if the year is a leap year or a common year, and then output the result.

bannerAds