Use C language to judge whether it is a leap year or a normal year

There are two ways to calculate leap years:
1) Divisible by 4 but not divisible by 100
2) Divisible by 400
#include <stdio.h>

int main()
{
    int year ;

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

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


    return 0;
}

Guess you like

Origin blog.csdn.net/m0_49456900/article/details/123851635