计算某天是一年中的第几天 很经典
很经典的题目:
当给你某个日期,让你计算该日期在该年中时第几天。
这里可以巧用switch语句。
程序如下:
int t_nMon; int t_nDay; cout << "输入月:"; cin >> t_nMon; cout << "输入天:"; cin >> t_nDay; int s_ndays = 0; switch(t_nMon-1) { case 12:s_ndays += 31; case 11:s_ndays += 30; case 10:s_ndays += 31; case 9:s_ndays += 30; case 8:s_ndays += 31; case 7:s_ndays += 31; case 6:s_ndays += 30; case 5:s_ndays += 31; case 4:s_ndays += 30; case 3:s_ndays += 31; case 2:s_ndays += 28; case 1:s_ndays += 31; } s_ndays = s_ndays + t_nDay; cout << s_ndays <<endl;