Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Namespace CalendarConsoleApp
{
Class Program
{
Static void Main (string [] args)
{
Console. WriteLine ("Enter the year and month ");
Int year = int. Parse (Console. ReadLine ());
Int month = int. Parse (Console. ReadLine ());
Int day = 0;
Int sum = 0;
For (int I = 1900; I <year; I ++)
{
If (I % 4 = 0 & I % 100! = 0 | I % 400 = 0)
{
Sum ++ = 366;
}
Else
{
Sum ++ = 365;
}
}
Switch (month)
{
Case 12:
Day = 31;
Break;
Case 11:
Day = 30;
Break;
Case 10:
Day = 31;
Break;
Case 9:
Day = 30;
Break;
Case 8:
Day = 31;
Break;
Case 7:
Day = 31;
Break;
Case 6:
Day = 30;
Break;
Case 5:
Day = 31;
Break;
Case 4:
Day = 30;
Break;
Case 3:
Day = 31;
Break;
Case 2:
If (year % 4 = 0 & amp; year % 100! = 0 | year % 400 = 0)
Day = 29;
Else
Day = 28;
Break;
Case 1:
Day = 31;
Break;
}
Int leap;
/* Calculate the total number of days of the month before a month */
Switch (month)
{
Case 1: sum + = 0; break;
Case 2: sum + = 31; break;
Case 3: sum + = 59; break;
Case 4: sum + = 90; break;
Case 5: sum ++ = 120; break;
Case 6: sum + = 151; break;
Case 7: sum + = 181; break;
Example 8: sum + = 212; break;
Case 9: sum ++ = 243; break;
Case 10: sum ++ = 273; break;
Case 11: sum ++ = 304; break;
Case 12: sum ++ = 334; break;
}
/* Determine whether it is a leap year */
If (year % 400 = 0 | (year % 4 = 0 & year % 100! = 0 ))
Leap = 1;
Else
Leap = 0;
/* If it is a leap year and the month is greater than 2, the total number of days should be added to one day */
If (leap = 1 & month> 2)
Sum ++;
Int space = (sum + 1) % 7;
Console. WriteLine ("day \ t one \ t Two \ t three \ t four \ t five \ t six \ t ");
For (int I = 1; I <= space + day; I ++)
{
If (I <= space)
Console. Write ("\ t ");
Else
Console. Write (I-space + "\ t ");
If (I % 7 = 0)
Console. WriteLine ();
}
Console. WriteLine ();
}
}
}
Else
Console. Write (I-space + "\ t ");
If (I % 7 = 0)
Console. WriteLine ();
}
Console. WriteLine ();
}
}
}
Author: lin_lujian