【C语言】打印1000年-2000年之间的闰年

解题思路:

1、闰年:能被4整除且不能被100整除的为闰年或能被400整除的年份。

2、程序实现:循环遍历1000-2000判断是否是闰年。

具体代码:

#include<stdio.h>
#include<stdlib.h>
int main(){
	printf("1000-2000年之间的闰年:\n");
	int year = 0;
	int count = 0;
	for (year = 1000; year <= 2000; year++){
		if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0){
			printf("%d  ", year);
			count++;
			if (count % 10 == 0){
				printf("\n");  //以十个一行打印
			}
		}
		continue;
	}
	printf("1000-2000之间闰年有%d个\n", count);
	system("pause");
	return 0;
}

运行结果:

【C语言】打印1000年-2000年之间的闰年