This is a water problem, but I still put it up, because I think I wrote the code is very beautiful (can I have a face?) )
The problem description is known as January 1, 2007 for Monday. Design a function to print a calendar after 2007 (including) a month of a year, before 2007, to reject printing. To complete this function, it is also necessary to design the necessary auxiliary functions. Sample input An input example that satisfies the requirements of the topic.
Cases:
2050 3 Sample output corresponds to the output of the sample input above.
Cases:
Data size and convention the range of each number in the input data.
Example: Year 2007-3000, Month: 1-12.
---------Split Line---------
1#include <stdio.h>2 intIs_leap_year (intYear )3 {4 return(year%4|| year% -==0&&year% -!=0)?0:1;5 }6 intYear_days (intYear )7 {8 returnIs_leap_year (year)?366:365;9 }Ten intMonth_days (intYearintmonth) One { A intDays ; - if(month==1|| month==3|| month==5|| month==7|| month==8|| month==Ten|| month== A) -days= to; the Else if(month!=2) -days= -; - if(month==2) - { + if(Is_leap_year (year)) -days= in; + Else Adays= -; at } - returnDays ; - } - intWeekintYearintmonth) - { - intday1=0; inmonth--; - while(month) to { +day1+=month_days (year,month); -month--; the } * while(year!= -) $ {Panax Notoginsengyear--; -day1+=year_days (year); the } + returnday1%7; A } the voidShowintYearintmonth) + { - intday1,t,i; $ if(month>=Ten) $printf"Calendar%d-%d\n", year,month); - Else -printf"Calendar%d-0%d\n", year,month); theprintf"---------------------\ n"); -printf"Su Mo Tu We Th Fr sa\n");Wuyiprintf"---------------------\ n"); theday1=Week (year,month); -t=day1+1; Wu while(t%7||t) - { Aboutprintf" "); $t--; - } - for(i=1; I<=month_days (year,month); i++) - { Aprintf"%2d", i); + if((i+day1+1)%7==0|| i==month_days (year,month)) theprintf"\ n"); - } $printf"---------------------\ n"); the } the intMain () the { the inty,m; -scanf"%d%d",&y,&m); in Show (y,m); the return 0; the}
Blue Bridge cup algorithm increases 5-3 calendar days