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

来源:互联网 发布:微信曾经打开淘宝链接 编辑:程序博客网 时间:2024/05/26 02:51
</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;}





0 0
原创粉丝点击