1. 程式人生 > >計算閏年,自定義範圍公元前100年到公元100年之間

計算閏年,自定義範圍公元前100年到公元100年之間

改變程式去掉year%100和year%400,從數學角度說,定義的年代小於除數而無意義,目的只在看計算後的元年前後的效果。

改變求閏年程式如下:

#include<stdio.h>
#define lower -100
#define upper 100
main()
{
int year;

for (year=lower; year<=upper; ++year)
{
if (year % 4 == 0)
printf("%d is a leap years\n", year);
else 
printf("%d is not a leap year\n", year);
}
}

ctrl+F5,執行結果僅供參考如下:

-100 is a leap years
-99 is not a leap year
-98 is not a leap year
-97 is not a leap year
-96 is a leap years
-95 is not a leap year
-94 is not a leap year
-93 is not a leap year
-92 is a leap years
-91 is not a leap year
-90 is not a leap year
-89 is not a leap year
-88 is a leap years
-87 is not a leap year
-86 is not a leap year
-85 is not a leap year
-84 is a leap years
-83 is not a leap year
-82 is not a leap year
-81 is not a leap year
-80 is a leap years
-79 is not a leap year
-78 is not a leap year
-77 is not a leap year
-76 is a leap years
-75 is not a leap year
-74 is not a leap year
-73 is not a leap year
-72 is a leap years
-71 is not a leap year
-70 is not a leap year
-69 is not a leap year
-68 is a leap years
-67 is not a leap year
-66 is not a leap year
-65 is not a leap year
-64 is a leap years
-63 is not a leap year
-62 is not a leap year
-61 is not a leap year
-60 is a leap years
-59 is not a leap year
-58 is not a leap year
-57 is not a leap year
-56 is a leap years
-55 is not a leap year
-54 is not a leap year
-53 is not a leap year
-52 is a leap years
-51 is not a leap year
-50 is not a leap year
-49 is not a leap year
-48 is a leap years
-47 is not a leap year
-46 is not a leap year
-45 is not a leap year
-44 is a leap years
-43 is not a leap year
-42 is not a leap year
-41 is not a leap year
-40 is a leap years
-39 is not a leap year
-38 is not a leap year
-37 is not a leap year
-36 is a leap years
-35 is not a leap year
-34 is not a leap year
-33 is not a leap year
-32 is a leap years
-31 is not a leap year
-30 is not a leap year
-29 is not a leap year
-28 is a leap years
-27 is not a leap year
-26 is not a leap year
-25 is not a leap year
-24 is a leap years
-23 is not a leap year
-22 is not a leap year
-21 is not a leap year
-20 is a leap years
-19 is not a leap year
-18 is not a leap year
-17 is not a leap year
-16 is a leap years
-15 is not a leap year
-14 is not a leap year
-13 is not a leap year
-12 is a leap years
-11 is not a leap year
-10 is not a leap year
-9 is not a leap year
-8 is a leap years
-7 is not a leap year
-6 is not a leap year
-5 is not a leap year
-4 is a leap years
-3 is not a leap year
-2 is not a leap year
-1 is not a leap year
0 is a leap years
1 is not a leap year
2 is not a leap year
3 is not a leap year
4 is a leap years
5 is not a leap year
6 is not a leap year
7 is not a leap year
8 is a leap years
9 is not a leap year
10 is not a leap year
11 is not a leap year
12 is a leap years
13 is not a leap year
14 is not a leap year
15 is not a leap year
16 is a leap years
17 is not a leap year
18 is not a leap year
19 is not a leap year
20 is a leap years
21 is not a leap year
22 is not a leap year
23 is not a leap year
24 is a leap years
25 is not a leap year
26 is not a leap year
27 is not a leap year
28 is a leap years
29 is not a leap year
30 is not a leap year
31 is not a leap year
32 is a leap years
33 is not a leap year
34 is not a leap year
35 is not a leap year
36 is a leap years
37 is not a leap year
38 is not a leap year
39 is not a leap year
40 is a leap years
41 is not a leap year
42 is not a leap year
43 is not a leap year
44 is a leap years
45 is not a leap year
46 is not a leap year
47 is not a leap year
48 is a leap years
49 is not a leap year
50 is not a leap year
51 is not a leap year
52 is a leap years
53 is not a leap year
54 is not a leap year
55 is not a leap year
56 is a leap years
57 is not a leap year
58 is not a leap year
59 is not a leap year
60 is a leap years
61 is not a leap year
62 is not a leap year
63 is not a leap year
64 is a leap years
65 is not a leap year
66 is not a leap year
67 is not a leap year
68 is a leap years
69 is not a leap year
70 is not a leap year
71 is not a leap year
72 is a leap years
73 is not a leap year
74 is not a leap year
75 is not a leap year
76 is a leap years
77 is not a leap year
78 is not a leap year
79 is not a leap year
80 is a leap years
81 is not a leap year
82 is not a leap year
83 is not a leap year
84 is a leap years
85 is not a leap year
86 is not a leap year
87 is not a leap year
88 is a leap years
89 is not a leap year
90 is not a leap year
91 is not a leap year
92 is a leap years
93 is not a leap year
94 is not a leap year
95 is not a leap year
96 is a leap years
97 is not a leap year
98 is not a leap year
99 is not a leap year
100 is a leap years
請按任意鍵繼續. . .