入学考试的测试题吗?:L话说我当时这道题直接没写...
给你个计算第几天的程序吧,
至于计算星期几,去网上查查蔡勒公式自己套吧.
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine(" |----------------------------------------------------------------|");
- Console.WriteLine(" | 这是一个“输入一个日期,求该日期是这一年中的第几天 ”的程序 |");
- Console.WriteLine(" |----------------------------------------------------------------|");
- Console.WriteLine();
- Console.WriteLine("您需要输入一个日期...");
- Console.WriteLine();
- Console.Write("您需要输入年份:");
- int year = int.Parse(Console.ReadLine());
- Console.WriteLine();
- Console.Write("您需要输入月份:");
- int month = int.Parse(Console.ReadLine());
- Console.WriteLine();
- Console.Write("您需要输入具体日期(几号?):");
- int date = int.Parse(Console.ReadLine());
- Console.WriteLine();
- Console.Write("{0}年{1}月{2}日是一年中的第", year, month, date);
- bool b = Leap_Common_year(year);//判断平年还是闰年
- switch (month) //判断月份
- {
- case 1: month_1(date); break;//根据日期计算出是哪一天
- case 2: month_2(date); break;
- case 3: month_3(date, b); break;
- case 4: month_4(date, b); break;
- case 5: month_5(date, b); break;
- case 6: month_6(date, b); break;
- case 7: month_7(date, b); break;
- case 8: month_8(date, b); break;
- case 9: month_9(date, b); break;
- case 10: month_10(date, b); break;
- case 11: month_11(date, b); break;
- case 12: month_12(date, b); break;
- default: Console.WriteLine("您输入的月份有误..."); break;
- }
- Console.ReadKey();
- }
- static bool Leap_Common_year(int year)//判断平年还是闰年
- {
- bool b;
- if (year % 4 == 0 && year % 100 != 0)
- {
- b = false;
- }
- else
- {
- b = true;
- }
- return b;
- }
- static void month_1(int date)
- {
- Console.Write("{0}天。", date);
- }
- static void month_2(int date)
- {
- int d;
- d = 31 + date;
- Console.Write("{0}天", d);
- }
- static void month_3(int date, bool b)
- {
- int d;
- if (b)
- {
- d = 31 + 28 + date;
- }
- else
- {
- d = 31 + 29 + date;
- }
- Console.Write("{0}天", d);
- }
- static void month_4(int date, bool b)
- {
- int d;
- if (b)
- {
- d = 31 + 28 + 31 + date;
- }
- else
- {
- d = 31 + 29 + 31 + date;
- }
- Console.Write("{0}天", d);
- }
- static void month_5(int date, bool b)
- {
- int d;
- if (b)
- {
- d = 31 + 28 + 31 + 30 + date;
- }
- else
- {
- d = 31 + 29 + 31 + 30 + date;
- }
- Console.Write("{0}天", d);
- }
- static void month_6(int date, bool b)
- {
- int d;
- if (b)
- {
- d = 31 + 28 + 31 + 30 + 31 + date;
- }
- else
- {
- d = 31 + 29 + 31 + 30 + 31 + date;
- }
- Console.Write("{0}天", d);
- }
- static void month_7(int date, bool b)
- {
- int d;
- if (b)
- {
- d = 31 + 28 + 31 + 30 + 31 + 30 + date;
- }
- else
- {
- d = 31 + 29 + 31 + 30 + 31 + 30 + date;
- }
- Console.Write("{0}天", d);
- }
- static void month_8(int date, bool b)
- {
- int d;
- if (b)
- {
- d = 31 + 28 + 31 + 30 + 31 + 30 + 31 + date;
- }
- else
- {
- d = 31 + 29 + 31 + 30 + 31 + 30 + 31 + date;
- }
- Console.Write("{0}天", d);
- }
- static void month_9(int date, bool b)
- {
- int d;
- if (b)
- {
- d = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + date;
- }
- else
- {
- d = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + date;
- }
- Console.Write("{0}天", d);
- }
- static void month_10(int date, bool b)
- {
- int d;
- if (b)
- {
- d = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + date;
- }
- else
- {
- d = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + date;
- }
- Console.Write("{0}天", d);
- }
- static void month_11(int date, bool b)
- {
- int d;
- if (b)
- {
- d = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + date;
- }
- else
- {
- d = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + date;
- }
- Console.Write("{0}天", d);
- }
- static void month_12(int date, bool b)
- {
- int d;
- if (b)
- {
- d = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + date;
- }
- else
- {
- d = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + date;
- }
- Console.Write("{0}天", d);
- }
- }
复制代码 |