如何求闰年

来源:互联网 发布:mac版word怎么看字数 编辑:程序博客网 时间:2024/06/10 13:11

闰年是公历中的名词,能被4整除但不能被100整除,或能被400整除的年份即为闰年。
输入两个年份,输出这两个年份区间中的闰年。

#include <stdio.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <algorithm>using namespace std;int f(int year){     if (year % 4  == 0 && year % 100 != 0  || year % 400 == 0)        return 1;     return 0;}int main(){    int y1,y2;    cin >> y1 >> y2;    for (int i = y1; i <= y2; ++i)    {        if(f(i))            printf("%d ",i);    }    return 0;}