判斷2000年---2500年之間的閏年


  分析閏年成立的條件:
ide

  (1)能被4整除,但不能被100整除的年份都是閏年,如1996年、2008年是閏年;it

  (2)能被400整除的年份是閏年,如1600年、2000年。io

  不符合這兩個條件的不是閏年,如2009年、2100年。class

  

#include<stdio.h>
int main()//判斷閏年
{
	int year,n=0;
	for (year = 2000; year <= 2500; year++)
	{
		if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
		{
			printf("%d ",year);
			n = n + 1;
			if (n%10==0)
			{
				printf("\n");
			}
		}
	}
	return 0;
}
相關文章
相關標籤/搜索