Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* 1.Leap if a it's a multiple of 4,eg:1996、2012、2016
- 2.Do not leap if it's a multiple of 100,eg:1800、1900、2100
- 3.Leap if a it's a multiple of 400,eg:1600、2000、2400
- 4.Do not leap if it's a multiple of 4000,eg:4000、8000 */
- #include <stdio.h>
- #include <stdlib.h>
- enum monthnumber
- {
- Jan = 1, Feb, Mar, April, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec
- }
- enum monthdays
- {
- Jan = 31, FebUsual = 28, FebLeap = 29, Mar = 31, April = 30, May = 31, Jun = 30, Jul = 31, Aug = 31,
- Sep = 30, Oct = 31, Nov = 30, Dec = 31
- }
- int JanFirstWeekDay(int year) // jan 1st of the assign year
- {
- // 1900 happens to be a multiple of 4 and 100 (No Leap) , Jan 1st of 1900 is monday , so i start from 1900
- // 365/7=52...1
- cycle = (year - 1900) / 4;
- single = (year - 1900) % 4;
- // every cycle (four years) passed , the week day of Jan 1st postponed by 5 days
- // every single (one year) passed , the week day of Jan 1st postponed by 1 days
- return (cycle * 5 + single);
- }
- int dayPassed(int year , int month) // day passed in assigned year until the assigned month
- {
- enum monthnumber month;
- single = (year - 1900) % 4;
- if (single == 0)
- FEB = 29;
- else
- FEB = 28;
- days
- }
- int main()
- {
- struct months calendar;
- int year = 0;
- int month = 0;
- int janFirstDay; // Jan 1st of the assign year
- int day; // day passed in the assigned month
- printf("which year? ( Between 1901 and 2099 ) \n");
- scanf("%d", &year);
- printf("which month? \n");
- scanf("%d", &month);
- janFirstDay = JanFirstWeekDay(year);
- 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;
- if (single == 0)
- {
- FEB = 29;
- }
- else
- {
- FEB = 28;
- }
- int day; // day passed in the assigned month
- if (month == 1)
- day = 0;
- if (month >= 2)
- day = JAN;
- if (month >= 3)
- day = day + FEB;
- if (month >= 4)
- day = day + MAR;
- if (month >= 5)
- day = day + APR;
- if (month >= 6)
- day = day + MAY;
- if (month >= 7)
- day = day + JUN;
- if (month >= 8)
- day = day + JUL;
- if (month >= 9)
- day = day + AUG;
- if (month >= 10)
- day = day + SEP;
- if (month >= 11)
- day = day + OCT;
- if (month >= 12)
- day = day + NOV;
- /*
- int totalday, weekday;
- totalday = janoneday + day;
- weekday = (totalday % 7) + 1; // 1900 jan 1st Monday
- // if weekday=1 , the first day of the assign month is Monday
- // if weekday=7 , the first day of the assign month is Sunday
- printf("_____________________________\n\n");
- printf(" %d ", year);
- if (month == 1)
- printf("January\n");
- if (month == 2)
- printf("Febuary\n");
- if (month == 3)
- printf("March\n");
- if (month == 4)
- printf("April\n");
- if (month == 5)
- printf("May\n");
- if (month == 6)
- printf("June\n");
- if (month == 7)
- printf("July\n");
- if (month == 8)
- printf("August\n");
- if (month == 9)
- printf("Septenber\n");
- if (month == 10)
- printf("October\n");
- if (month == 11)
- printf("Novenber\n");
- if (month == 12)
- printf("December\n");
- printf("_____________________________\n");
- printf(" SUN MON TUE WED THU FRI SAT\n");
- int i = 1, calentotal;
- weekday = weekday + 1; // because on the calender Sunday is first day
- // now weekday doesn't stands for "what day is the day" but stands for which colume is the day
- if (weekday == 8)
- {
- weekday = 1;
- }
- printf(" ");
- // Start Printing
- while (i < weekday)
- {
- printf(" ");
- i = i + 1;
- }
- // the first week
- while (i >= weekday && i <= 7)
- {
- printf(" %d ", (i - weekday + 1));
- i = i + 1;
- }
- printf("\n");
- printf(" ");
- // the second week
- while (i > 7 && i < weekday + 9)
- {
- printf(" %d ", (i - weekday + 1));
- if ((i % 7) == 0)
- {
- printf("\n");
- printf(" ");
- }
- i = i + 1;
- }
- // days after 10th
- int monthday; // how many days for the assigned month
- if (month == 1)
- monthday = JAN;
- if (month == 2)
- monthday = FEB;
- if (month == 3)
- monthday = MAR;
- if (month == 4)
- monthday = APR;
- if (month == 5)
- monthday = MAY;
- if (month == 6)
- monthday = JUN;
- if (month == 7)
- monthday = JUL;
- if (month == 8)
- monthday = AUG;
- if (month == 9)
- monthday = SEP;
- if (month == 10)
- monthday = OCT;
- if (month == 11)
- monthday = NOV;
- if (month == 12)
- monthday = DEC;
- calentotal = weekday + monthday;
- while (i < calentotal)
- {
- printf("%d ", (i - weekday + 1));
- if ((i % 7) == 0)
- {
- printf("\n");
- printf(" ");
- }
- i = i + 1;
- }
- printf("\n");
- printf("_____________________________\n\n");
- */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement