闰年是公历中的名词,能被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;
}