输入年月日,输出这一天是这一年的多少天
while (true) { Console.Write("请输入年份:"); int a = int.Parse(Console.ReadLine()); Console.Write("请输入月份:"); int b = int.Parse(Console.ReadLine()); Console.Write("请输入几号:"); int c = int.Parse(Console.ReadLine()); int d; if (a > 9999 || a < 1759 || b <= 0 || b > 12 || c <= 0 || c > 31 || ((b == 4 || b == 6 || b == 9 || b == 11) && c > 30)) { Console.WriteLine("您输入的日期有误"); } else { if (a % 400 == 0 || (a % 100 != 0 && a % 4 == 0)) { if (b < 2) { d = c; Console.WriteLine("这是这一年的第" + d + "天"); } if (b == 2) { if (c > 29) { Console.WriteLine("您输入的日期有误"); } else { d = c + 31; Console.WriteLine("这是这一年的第" + d + "天"); } } if (b > 2 && b < 8) { if (b % 2 == 0) { d = b / 2 * 31 + (b / 2 - 2) * 30 + 29 + c; Console.WriteLine("这是这一年的第" + d + "天"); } if (b % 2 != 0) { d = (b - 1) / 2 * 31 + ((b - 1) / 2 - 1) * 30 + 29 + c; Console.WriteLine("这是这一年的第" + d + "天"); } } if (b >= 8) { if (b % 2 == 0) { d = (b - 8) / 2 * 31 + (b - 8) / 2 * 30 + 31 * 4 + 30 * 2 + 29 + c; Console.WriteLine("这是这一年的第" + d + "天"); } else { d = (b - 7) / 2 * 31 + ((b - 7) / 2 - 1) * 30 + 31 * 4 + 30 * 2 + 29 + c; Console.WriteLine("这是这一年的第" + d + "天"); } } } else { if (b < 2) { d = c; Console.WriteLine("这是这一年的第" + d + "天"); } if (b == 2) { if (c > 28) { Console.WriteLine("您输入的日期有误"); } else { d = c + 31; Console.WriteLine("这是这一年的第" + d + "天"); } } if (b > 2 && b < 8) { if (b % 2 == 0) { d = b / 2 * 31 + (b / 2 - 2) * 30 + 28 + c; Console.WriteLine("这是这一年的第" + d + "天"); } else { d = (b - 1) / 2 * 31 + ((b - 1) / 2 - 1) * 30 + 28 + c; Console.WriteLine("这是这一年的第" + d + "天"); } } if (b >= 8) { if (b % 2 == 0) { d = (b - 8) / 2 * 31 + ((b - 8) / 2) * 30 + 31 * 4 + 28 + 30 * 2 + c; Console.WriteLine("这是这一年的第" + d + "天"); } else { d = (b - 7) / 2 * 31 + ((b - 7) / 2 - 1) * 30 + 31 * 4 + 28 + 30 * 2 + c; Console.WriteLine("这是这一年的第" + d + "天"); } } } } }