判断1000到2000年里的闰年

闰年的判断条件是,能被4整除同时不能被100整除,或者能被400整除的年份。
由此可以写出以下代码,判断1000年到2000年之间的闰年。

#include <stdio.h>

int main()
{
      int year;
      for(year=1000;year<=2000;year++)
     {
      if((year % 4 == 0 && year % 100 != 0)||(year % 400 == 0))
              printf("%d是闰年\n",year);
     }
     return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_42978418/article/details/82748145