. 1 #include <stdio.h> 2 . 3 . 4 void WNL ( int Y); . 5 . 6 int main ( void ) . 7 { . 8 int year; . 9 the printf ( " Please enter the year (greater than 1990): " ); 10 Scanf ( " D% " , & year); . 11 WNL (year); // call the function WNL calendar year print 12 is return 0 ; 13 is } 14 15 / * 16 function: printing calendar 17 Function Parameters: Year 18 Function Return Value: None 19 Note: None 20 is * / 21 is void WNL ( int Y) { 22 is // . 1. 5. 4. 3 2. 6. 7. 8. 9. 11 10 12 is 23 is // 31 is 31 is 28 30 31 is 31 31 30 31 30 30 31 24- int Mon; 25 int RN = 0 ; // leap year mark 26 int SUM = 0 ; // store the number of days 27 int mon_one_day = 0 ; // know every month on the first day of the week 28 int= mon_days 0 ; // total number of days each month storage 29 int I, J = 0 ; 30 int K = 0 ; 31 is 32 int W = (Y + (Y - . 1 ) / . 4 - (Y - . 1 ) / 100 + (Y - . 1 ) / 400 )% . 7 ; // record the required number of the week on the first day of the year 33 is 34 is IF ((Y% . 4 == 0 ) && (Y% 100 ! = 0 ) || (Y% 400 == 0 )) // leap 35 { 36 RN = . 1 ; 37 [ } 38 is 39 for (Mon = . 1 ; Mon <= 12 is ; Mon ++ ) 40 { 41 is 42 is SUM = 0 ; // Total Days 43 is mon_days = 0 ; // month days 44 is mon_one_day = 0 ; // first month, day of the week for recording the number of 45 J = K; 46 is 47 Switch (Mon)// record the number of days per month of 48 { 49 Case 12 is : mon_days = 31 is ; BREAK ; 50 Case . 11 : mon_days = 30 ; BREAK ; 51 is Case 10 : mon_days = 31 is ; BREAK ; 52 is Case . 9 : mon_days = 30 ; BREAK ; 53 is Case . 8 : mon_days = 31 is ; BREAK ; 54 is Case . 7 : mon_days = 31 is; break; 55 case 6: mon_days = 30; break; 56 case 5: mon_days = 31; break; 57 case 4: mon_days = 30; break; 58 case 3: mon_days = 31; break; 59 case 2: mon_days = 28 + rn; break; //加上闰年(0或1) 60 case 1: mon_days = 31; BREAK ; 61 is } 62 is 63 is Switch (Mon) // number of records from January to the current month of days 64 { 65 Case 12 is : SUM + = 30 ; 66 Case . 11 : SUM + = 31 is ; 67 Case 10 : SUM + = 30 ; 68 Case . 9 : SUM = + 31 is ; 69 Case . 8 : SUM = + 31 is ; 70 Case . 7 : SUM = + 30 ; 71 is Case . 6 : SUM + = 31 is ; 72 Case . 5 : SUM + = 30 ; 73 is Case . 4 : SUM + = 31 is ; 74 Case . 3 : SUM + = 28 + RN; 75 Case 2 : SUM + = 31 is ; 76 Case . 1 : + = SUM 0 ; 77 } 78 79 SUM = + (w to . 1 ); // subtracting day 80 mon_one_day% = SUM . 7 ; // weeks of each month on the first day of 81 82 / * ******** print ********** * / 83 printf ( " / ********* **% d month ************** / \ R & lt \ n- " , Mon); 84 the printf ( " MTWTFSS \ R & lt \ n- " ); 85 86 87 for (I = 0 ; I <mon_one_day; I ++) // align 88 { 89 the printf ( " " ); 90 J ++ ; 91 is } 92 93 for(I = . 1 ; I <= mon_days; I ++ ) 94 { 95 the printf ( " % 4D " , I); // Align 96 J ++ ; 97 IF (J% . 7 == 0 ) // every 7 days for line 98 { 99 the printf ( " \ R & lt \ n- " ); 100 } 101 } 102 103 the printf ( " \ R & lt \ n- " ); 104 } 105 }
Note: This program can be used as the basic C language statements job title
Note: switch statement if there is no break, after completion of the operation will continue to run after the jump statement statement, for example,
run:
int i = 1,sum = 0;
Switch (I) {
Case 1: = SUM + 1 ; Case 2: = SUM + 2 ; Case 3: SUM + = 3 ; }
after, sum is 0 + 2 + 1 + 3 = 6