int year, month, day,sum=0;
int[] monthday = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
Console.WriteLine("请输入年份");
编写c#程序,实现接收用户输入的日期,并统计该日期是一年中的第几天。
year = int.Parse(Console.ReadLine());
Console.WriteLine("请输入月份");
month = int.Parse(Console.ReadLine());
Console.WriteLine("请输入日期");
day = int.Parse(Console.ReadLine());
//其中,闰年4年一次
if (year % 400 == 0 || (year % 100 == 0 && year % 4 != 0))
{
monthday[1] = 29;
}
Console.WriteLine(year+"年"+month+"月"+day+"日");
for (int i = 0; i<month-1; i++)
{
sum += monthday[i];
}
Console.WriteLine("是今年的第" + (sum + day) + "天");
Console.ReadLine();