Simple calendar in C language,
Simple calendar written in C language, the Code is as follows:
# Include <stdio. h> int main (int argc, const char * argv []) {// insert code here .. int year, month, day = 0, day1 = 0; printf ("Enter the year:"); scanf ("% d", & year ); printf ("Enter the month:"); scanf ("% d", & month ); printf ("one \ t Two \ t three \ t four \ t five \ t six \ t day \ n "); // determine whether the year is a leap year or this year for (int I = 1900; I <year; I ++) {if (I % 4 = 0 & I % 100! = 0) | I % 400 = 0) {day = day + 366;} else {day = day + 365 ;}} // determine the month for (int m = 1; m <= month; m ++) {switch (m) {case 4: case 6: case 9: case 11: day1 = 30; break; case 2: if (year % 4 = 0 & year % 100! = 0) | year % 400 = 0) {day1 = 29;} else {day1 = 28;} break; default: day1 = 31; break ;} if (m <month) {day = day + day1 ;}} int t; t = day % 7; // determine the day of the week on the first day of the month (int I = 0; I <t; I ++) {printf ("\ t ");} // control format: for (int I = 1; I <= day1; I ++) {printf ("% d \ t", I); if (I + day) % 7 = 0) {printf ("\ n") ;}} printf ("\ n"); return 0 ;}
The running effect is as follows: