#include <stdio.h>

//判断闰年函数
int isLeapYear(int year){
    if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0){
        return 1;   //是闰年,返回1
    } else {
        return 0;   //不是闰年,返回0
    }
}

int main(){
    int year;
    for(year = 1; year <= 10000; year++){
        if(isLeapYear(year)){   //如果是闰年
            printf("%d\n", year);   //输出年份
        }
    }
    return 0;
}

注:闰年的判断规则为:能被4整除但不能被100整除的年份为普通闰年,能被400整除的为世纪闰年。

设计算法并编写程序求出公元1~10000年中的所有闰年。用函数实现使用c语言附带注释

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

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