方法一:
#include<stdio.h>
int main()
{
int i = 0;
int count = 0;
for (i = 1000; i <= 2000; i++)
{
if ((i % 4 == 0 && i % 100 != 0) || (i % 400 == 0))
{
printf("%d ", i);
count++;
}
}
printf("%d", count);
return 0;
}
方法二:
int is_leap_year(int i)
{
if (((i % 4 == 0) && (i % 100 != 0)) || (i % 400 == 0))
{
return 1;
}
else
return 0;
}
int main()
{
int i = 0;
for (i = 1000; i <= 2000; i++)
{
if (is_leap_year(i) == 1)
{
printf("%d ", i);
}
}
return 0;
}