#include <stdio.h>

int main() { int year; int hasLeapYear = 0;

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

printf("21世纪中截至%d年之前的所有闰年年份为:", year);

for (int i = 2001; i <= year; i++)
{
    if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0)
    {
        printf("%d ", i);
        hasLeapYear = 1;
    }
}

if (!hasLeapYear)
{
    printf("None");
}

printf("\n");

return 0;

}

这段代码将根据用户输入的年份,计算从2001年到输入年份(包括该年份)之间的闰年年份,并将结果打印出来。如果没有闰年,则会输出'None'。

C语言代码:计算21世纪闰年并输出

原文地址: https://www.cveoy.top/t/topic/bhhT 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录