判断闰年(函数)的方法

判断闰年

#include<stdio.h>
#include<math.h>
#include<stdbool.h>
//判断闰年
bool Is_Leapyear(int year)
{
    if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
        return true;
    else
        return false;
}
int main()
{
    while (1)
    {
        int year;
        printf("请输入年份:");
        scanf("%d", &year);
        if (Is_Leapyear(year))
            printf("%d是闰年\n\n", year);
        else
            printf("%d不是闰年\n\n", year);
    }
    system("pause");
    return 0;
}

猜你喜欢

转载自blog.csdn.net/wsq119/article/details/80627818