闰年个数(非循环)

#include <stdio.h>
int main()
{
	int n, i, count = 0, test;
	scanf("%d", &n);
	for (i = 1; i <= n; ++i)// 循环版 
	{
		if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0)
		{
			++count;
		}
	}
	// 非循环 
	test = n / 4 - n / 100 + n / 400;// 直接算闰年个数,不用循环 
	printf("test: %d\ncount: %d", test, count);
	return 0;
}


========================================Talk is cheap, show me the code=======================================
posted @ 2018-02-27 15:57  绿叶萌飞  阅读(145)  评论(0编辑  收藏  举报