This is still very practical ....
Header file:
#ifndef Main_h#defineMain_h#include"stdio.h"#include"math.h"#include"stdlib.h"//get the maximum number of days for a one monthintMonthDay (int,int );//Judging leap Year, is returning 1, not returning 0intIsleapyear (int );#endif
Main function:
#include"Main.h"intMain () {intYear,month,days,weekday; inti,d; while(1) {printf ("Please input the year:\n"); scanf ("%d",&Year ); days= year-1+ (year-1)/ -+ (year-1)/4-(year-1)/ -;//calculate the first day of the year is the days of the week for(month=1; month<= A; month++) {printf ("\t\t****%d year--%d month ****\n", Year,month); printf ("sun\tmon\ttues\twed\tthur\tfir\tsat\t\n");//Table Headeri =1; D =1; Weekday= (days +1)%7;//ask for the day of the week while(I<=weekday)//output the preceding space{printf ("\ t"); I++; } while(D<=monthday (Month,year))//Output Date{Weekday= (days +1)%7; if(weekday==6)//The last one is Saturday, and the output will be wrapped.printf"%d\n", D); Else //No line break after Saturday outputprintf"%d\t", D); if(d==MonthDay (month,year)) printf ("\ n"); D++; days++; } } } }
function function Implementation:
#include"Main.h"intMonthDay (intMonthintYear ) { Switch(month) { Case 1: Case 3: Case 5: Case 7: Case 8: Case Ten: Case A: return to; Break; Case 4: Case 6: Case 9: Case One: return -; Break; Case 2: if(Isleapyear (year)) {return in;//leap year 29 days Break; } Else { return -; Break; } } }intIsleapyear (intYear ) { if((year%4==0) && (year% -!=0)|| (year% -==0)) return 1; Else return 0;}
:
C Language Implementation Calendar output