int i, year, month, week, days = 0, day=0;
do
{
days = 0;
Console.WriteLine("请输入年份:");
year = int.Parse(Console.ReadLine());
Console.WriteLine("请输入月份:");
month =int.Parse(Console.ReadLine());
for (i = 1900; i < year; i++)
{
if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) days = days + 366;
else days = days + 365;
}
for (i = 1; i < month; i++)
{
switch (i)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: days = days + 31; break;
case 4:
case 6:
case 9:
case 11: days = days + 30; break;
case 2:
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
days = days + 29;
else days = days + 28;
break;
}
}
week = (days + 1) % 7;
Console.WriteLine("星期天\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六\n");
for (i = 0; i < week; i++)
{
Console.Write("\t");
}
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: day = 31; break;
case 4:
case 6:
case 9:
case 11: day = 30; break;
case 2:
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
day = 29;
else day = 28;
break;
}
for (i = 1; i <= day; i++)
{
if ((week + i - 1) % 7 == 0) Console.WriteLine();
Console.Write("{0}\t", i);
}
Console.WriteLine();
} while (true);
do
{
days = 0;
Console.WriteLine("请输入年份:");
year = int.Parse(Console.ReadLine());
Console.WriteLine("请输入月份:");
month =int.Parse(Console.ReadLine());
for (i = 1900; i < year; i++)
{
if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) days = days + 366;
else days = days + 365;
}
for (i = 1; i < month; i++)
{
switch (i)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: days = days + 31; break;
case 4:
case 6:
case 9:
case 11: days = days + 30; break;
case 2:
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
days = days + 29;
else days = days + 28;
break;
}
}
week = (days + 1) % 7;
Console.WriteLine("星期天\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六\n");
for (i = 0; i < week; i++)
{
Console.Write("\t");
}
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: day = 31; break;
case 4:
case 6:
case 9:
case 11: day = 30; break;
case 2:
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
day = 29;
else day = 28;
break;
}
for (i = 1; i <= day; i++)
{
if ((week + i - 1) % 7 == 0) Console.WriteLine();
Console.Write("{0}\t", i);
}
Console.WriteLine();
} while (true);