华东医药招聘云南:输入任意一个日期,判断其是当年的第几天

来源:百度文库 编辑:中科新闻网 时间:2024/05/06 18:54:03
这是一道C++的编程题

判断已经过去的月份天数和当月的天数不就可以了!
比如
int year, month, day;
int totaldays = 0;
//初始化年,月,日..........
int daysofmonth[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

//计算今年是否是闰年
if ((year % 100 != 0 && year % 4 == 0 ) || year % 400 == 0)
{
//如果是闰年,则二月为29天
daysofmonth[2] = 29;
}

//将每月的天数相加
for (int i = 1; i < month; i++ )
{
totaldays += daysofmonth[i];
}

//再加上本月的天数
totaldays += day;