• API
• FAQ
• Tools
• Archive
SHARE
TWEET Untitled a guest May 23rd, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. /* 1.Leap if a it's a multiple of 4，eg：1996、2012、2016
2.    2.Do not leap if it's a multiple of 100，eg：1800、1900、2100
3.    3.Leap if a it's a multiple of 400，eg：1600、2000、2400
4.    4.Do not leap if it's a multiple of 4000，eg：4000、8000 */
5.
6. #include <stdio.h>
7. #include <stdlib.h>
8.
9. enum monthnumber
10. {
11.     Jan = 1, Feb, Mar, April, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec
12. }
13.
14. enum monthdays
15. {
16.     Jan = 31, FebUsual = 28, FebLeap = 29, Mar = 31, April = 30, May = 31, Jun = 30, Jul = 31, Aug = 31,
17.     Sep = 30, Oct = 31, Nov = 30, Dec = 31
18. }
19.
20. int JanFirstWeekDay(int year) // jan 1st of the assign year
21. {
22.     // 1900 happens to be a multiple of 4 and 100 (No Leap) , Jan 1st of 1900 is monday , so i start from 1900
23.     // 365/7=52...1
24.     cycle = (year - 1900) / 4;
25.     single = (year - 1900) % 4;
26.
27.     // every cycle (four years) passed , the week day of Jan 1st postponed by 5 days
28.     // every single (one year) passed , the week day of Jan 1st postponed by 1 days
29.     return (cycle * 5 + single);
30. }
31.
32.
33. int dayPassed(int year , int month) // day passed in assigned year until the assigned month
34. {
35.     enum monthnumber month;
36.
37.     single = (year - 1900) % 4;
38.     if (single == 0)
39.         FEB = 29;
40.     else
41.         FEB = 28;
42.
43.
44.     days
45. }
46.
47. int main()
48. {
49.     struct months calendar;
50.     int year = 0;
51.     int month = 0;
52.     int janFirstDay; // Jan 1st of the assign year
53.     int day; // day passed in the assigned month
54.
55.     printf("which year? ( Between 1901 and 2099 ) \n");
56.     scanf("%d", &year);
57.     printf("which month? \n");
58.     scanf("%d", &month);
59.
60.     janFirstDay = JanFirstWeekDay(year);
61.
62.
63.     int JAN = 31, FEB = 29, MAR = 31, APR = 30, MAY = 31, JUN = 30, JUL = 31, AUG = 31, SEP = 30, OCT = 31, NOV = 30, DEC = 31;
64.
65.     if (single == 0)
66.     {
67.         FEB = 29;
68.     }
69.
70.     else
71.     {
72.         FEB = 28;
73.     }
74.
75.
76.
77.     int day; // day passed in the assigned month
78.
79.     if (month == 1)
80.         day = 0;
81.     if (month >= 2)
82.         day = JAN;
83.     if (month >= 3)
84.         day = day + FEB;
85.     if (month >= 4)
86.         day = day + MAR;
87.     if (month >= 5)
88.         day = day + APR;
89.     if (month >= 6)
90.         day = day + MAY;
91.     if (month >= 7)
92.         day = day + JUN;
93.     if (month >= 8)
94.         day = day + JUL;
95.     if (month >= 9)
96.         day = day + AUG;
97.     if (month >= 10)
98.         day = day + SEP;
99.     if (month >= 11)
100.         day = day + OCT;
101.     if (month >= 12)
102.         day = day + NOV;
103.
104.     /*
105.     int totalday, weekday;
106.
107.     totalday = janoneday + day;
108.     weekday = (totalday % 7) + 1; // 1900 jan 1st Monday
109.
110.     // if weekday=1 , the first day of the assign month is Monday
111.     // if weekday=7 , the first day of the assign month is Sunday
112.
113.     printf("_____________________________\n\n");
114.     printf("       %d    ", year);
115.
116.     if (month == 1)
117.         printf("January\n");
118.     if (month == 2)
119.         printf("Febuary\n");
120.     if (month == 3)
121.         printf("March\n");
122.     if (month == 4)
123.         printf("April\n");
124.     if (month == 5)
125.         printf("May\n");
126.     if (month == 6)
127.         printf("June\n");
128.     if (month == 7)
129.         printf("July\n");
130.     if (month == 8)
131.         printf("August\n");
132.     if (month == 9)
133.         printf("Septenber\n");
134.     if (month == 10)
135.         printf("October\n");
136.     if (month == 11)
137.         printf("Novenber\n");
138.     if (month == 12)
139.         printf("December\n");
140.
141.     printf("_____________________________\n");
142.     printf(" SUN MON TUE WED THU FRI SAT\n");
143.
144.     int i = 1, calentotal;
145.
146.     weekday = weekday + 1; // because on the calender Sunday is first day
147.
148.     // now weekday doesn't stands for "what day is the day" but stands for which colume is the day
149.
150.     if (weekday == 8)
151.     {
152.         weekday = 1;
153.     }
154.
155.     printf("  ");
156.
157.     // Start Printing
158.
159.     while (i < weekday)
160.     {
161.         printf("    ");
162.         i = i + 1;
163.     }
164.
165.     // the first week
166.
167.     while (i >= weekday && i <= 7)
168.     {
169.         printf(" %d  ", (i - weekday + 1));
170.         i = i + 1;
171.     }
172.
173.     printf("\n");
174.     printf("  ");
175.
176.     // the second week
177.
178.     while (i > 7 && i < weekday + 9)
179.     {
180.         printf(" %d  ", (i - weekday + 1));
181.
182.         if ((i % 7) == 0)
183.         {
184.             printf("\n");
185.             printf("  ");
186.         }
187.         i = i + 1;
188.     }
189.
190.     // days after 10th
191.
192.     int monthday; // how many days for the assigned month
193.
194.     if (month == 1)
195.         monthday = JAN;
196.     if (month == 2)
197.         monthday = FEB;
198.     if (month == 3)
199.         monthday = MAR;
200.     if (month == 4)
201.         monthday = APR;
202.     if (month == 5)
203.         monthday = MAY;
204.     if (month == 6)
205.         monthday = JUN;
206.     if (month == 7)
207.         monthday = JUL;
208.     if (month == 8)
209.         monthday = AUG;
210.     if (month == 9)
211.         monthday = SEP;
212.     if (month == 10)
213.         monthday = OCT;
214.     if (month == 11)
215.         monthday = NOV;
216.     if (month == 12)
217.         monthday = DEC;
218.
219.     calentotal = weekday + monthday;
220.
221.     while (i < calentotal)
222.     {
223.         printf("%d  ", (i - weekday + 1));
224.
225.         if ((i % 7) == 0)
226.         {
227.             printf("\n");
228.             printf("  ");
229.         }
230.
231.         i = i + 1;
232.     }
233.
234.     printf("\n");
235.     printf("_____________________________\n\n");
236.     */
237.     return 0;
238. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top