using System;
using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1
{ class Program { static void Main(string[] args) {/*实现年份月份*/ Console.WriteLine("请输入年份(1900-2100):"); int year,month; year=int.Parse(Console.ReadLine()); while (year < 1900 || year > 2100) { Console.WriteLine("请输入正确的年份(1900-2100):");year = int.Parse(Console.ReadLine());
} Console.WriteLine("请输入月份(1-12):"); month = int.Parse(Console.ReadLine());while (month < 1 || month > 12)
{ Console.WriteLine("请输入正确的月份(1-12):");month = int.Parse(Console.ReadLine());
}/*计算某年某月到1990年1月1日的天数*/
int acrossyear,acrossmonth,days=0; for(acrossyear=1900;acrossyear<year;acrossyear++) {if(acrossyear%4==0&&acrossyear%100!=0||acrossyear%400==0) days+=366; else days+=365;} for (acrossmonth = 1; acrossmonth < month; acrossmonth++) if (acrossmonth == 2) { if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) days += 29; else days += 28; } else if (acrossmonth < 8 && acrossmonth % 2 != 0 || acrossmonth > 7 && acrossmonth % 2 == 0) days += 31; else days += 30;int numblank; numblank=days%7+1;//计算空白数量 List<string>a=new List<string>();//创建某个月日历的集合 int i; for(i=1;i<=numblank;i++) a.Add(" "); /*求某月的天数*/ int ts,j; if(month==2) {if(year% 4 == 0 && year % 100 != 0 || year % 400 == 0) ts=29; else ts=28;} else if(acrossmonth < 8 && acrossmonth % 2 != 0 || acrossmonth > 7 && acrossmonth % 2 == 0) ts=31; else ts=30; for(j=1;j<=ts;j++) a.Add(j.ToString());//创建日历集合 /*输出日历*/ Console.WriteLine("****************************************************************"); Console.Write("日"+"\t"+"一"+"\t"+"二"+"\t"+"三"+"\t"+"四"+"\t"+"五"+"\t"+"六"); int k = a.Count(); int x; for (x = 0; x < k; x++) { if (x % 7 == 0) Console.WriteLine("\n"); Console.Write(a[x] + "\t"); } Console.WriteLine("\n"+"****************************************************************"); Console.WriteLine("程序结束,请按确认键结束");
}
}}