请根据以下要求,编写一段C程序代码:(1)统计1800年至2200年之间一共有多少个闰年,并把闰年的个数输出到屏幕;
供参考:
#include<stdio.h>
int main()
{
int y,cnt=0;
for(y=1800;y<=2200;y++)
if((y%4==0 && y%100!=0)||(y%400==0)){
cnt++;
}
printf("count:%d\n",cnt);
return 0;
}
代码如下:
#include <iostream>
using namespace std;
int main()
{
for (int year = 1800; year <= 2200; year++)
{
if (year % 4 == 0 && year % 100 != 0)
cout << year << endl;
else if(year % 100 == 0 && year % 400 == 0)
cout << year << endl;
}
return 0;
}