Use the formula Jim larerson. For details, refer to elementary number theory. Pay attention to the control format.
C ++ kids shoes are hard to understand, all cin is interpreted as scanf, and cout is interpreted as printf. This program was written when I was a child and I didn't want to change it.
[Cpp]
# Include "iostream"
Using namespace std;
Int main ()
{
Int m, d, monthmax, y;
While (1)
{
Cout <"Enter the year :";
Cin> y;
Cout <"Enter the month :";
Cin> m;
Cout <endl;
// Determine the year and month
If (y % 4 = 0 | (y % 100 = 0 & y % 400 = 0) // leap year
{
If (m = 1 | m = 3 | m = 5 | m = 7 | m = 8 | m = 10 | m = = 12)
Monthmax = 31;
If (m = 2)
Monthmax = 29;
If (m = 4 | m = 6 | m = 9 | m = 11)
Monthmax = 30;
}
If (y % 4! = 0) // year
{
If (m = 1 | m = 3 | m = 5 | m = 7 | m = 8 | m = 10 | m = = 12)
Monthmax = 31;
If (m = 2)
Monthmax = 28;
If (m = 4 | m = 6 | m = 9 | m = 11)
Monthmax = 30;
}
// The number of week 1 obtained by the kemlerson Formula
If (m = 1 | m = 2)
{
M + = 12; // The year January is counted as the 13 months of the previous year, and the year February is counted as the 14 months of the previous year.
Y --;
}
D = (2 + 2 * m + 3 * (m + 1)/5 + y/4-y/100 + y/400) % 7; // calculate the day of week 1 of this month
If (d = 0)
{
D = 7;
}
// Output calendar
{
{
// Title Module
If (m = 13)
{
Cout <"ad" <y + 1 <"1st Calendar" <endl;
}
If (m = 14)
{
Cout <"ad" <y + 1 <"2nd Calendar" <endl;
}
If (m! = 13 & m! = 14)
{
Cout <"ad" <y <"" <m <"Monthly Calendar" <endl;
}
}
Cout <"1 2 3 4 5 6 7" <endl <"==================== ===== "<endl;
For (int I = 1; I <= D-1; I ++)
{
Cout <"";
}
For (int j = 1; j <= monthmax; j ++)
{
If (j <10)
{
Cout <"" <j <"";
}
If (j> = 10)
{
Cout <"" <j <"";
}
If (j + D-1) % 7 = 0)
{
Cout <endl;
}
If (j = monthmax)
{
Cout <endl;
}
}
Cout <endl;
}
}
}
# Include "iostream"
Using namespace std;
Int main ()
{
Int m, d, monthmax, y;
While (1)
{
Cout <"Enter the year :";
Cin> y;
Cout <"Enter the month :";
Cin> m;
Cout <endl;
// Determine the year and month
If (y % 4 = 0 | (y % 100 = 0 & y % 400 = 0) // leap year
{
If (m = 1 | m = 3 | m = 5 | m = 7 | m = 8 | m = 10 | m = = 12)
Monthmax = 31;
If (m = 2)
Monthmax = 29;
If (m = 4 | m = 6 | m = 9 | m = 11)
Monthmax = 30;
}
If (y % 4! = 0) // year
{
If (m = 1 | m = 3 | m = 5 | m = 7 | m = 8 | m = 10 | m = = 12)
Monthmax = 31;
If (m = 2)
Monthmax = 28;
If (m = 4 | m = 6 | m = 9 | m = 11)
Monthmax = 30;
}
// The number of week 1 obtained by the kemlerson Formula
If (m = 1 | m = 2)
{
M + = 12; // The year January is counted as the 13 months of the previous year, and the year February is counted as the 14 months of the previous year.
Y --;
}
D = (2 + 2 * m + 3 * (m + 1)/5 + y/4-y/100 + y/400) % 7; // calculate the day of week 1 of this month
If (d = 0)
{
D = 7;
}
// Output calendar
{
{
// Title Module
If (m = 13)
{
Cout <"ad" <y + 1 <"1st Calendar" <endl;
}
If (m = 14)
{
Cout <"ad" <y + 1 <"2nd Calendar" <endl;
}
If (m! = 13 & m! = 14)
{
Cout <"ad" <y <"" <m <"Monthly Calendar" <endl;
}
}
Cout <"1 2 3 4 5 6 7" <endl <"==================== ===== "<endl;
For (int I = 1; I <= D-1; I ++)
{
Cout <"";
}
For (int j = 1; j <= monthmax; j ++)
{
If (j <10)
{
Cout <"" <j <"";
}
If (j> = 10)
{
Cout <"" <j <"";
}
If (j + D-1) % 7 = 0)
{
Cout <endl;
}
If (j = monthmax)
{
Cout <endl;
}
}
Cout <endl;
}
}
}