天天看点

C语言打印1000-2000年里的闰年

</pre><pre name="code" class="cpp">
           

1.

<pre name="code" class="cpp">#include "stdio.h"


int main()
{
	int year = 0;
	int i = 0;
	int count = 0;
	for (year = 1000; year <= 2000; year++)
	{
		if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
		{
			count += 1;
			printf("%d ", year);
		}
	}
	printf("\ncount=%d ", count);
	getchar();
	return 0;
}
           

2.

#include "stdio.h"
#include "math.h"

int main()
{
	int i = 100;
	int j;
	int count = 0;
	for (i = 101; i <= 199; i = i + 2)
	{
		for (j = 2; j <= sqrt(i); j++)
			if (i%j == 0)
			    break;
		if (j > sqrt(i))
		{
			count += 1;
			printf("%d  ", i);
		}
	}
	printf("\ncount=%d", count);
	system("pause");
	return 0;
}
           
C语言打印1000-2000年里的闰年

继续阅读