用C++编写一个程序,输入年月日,输出该天是该年的第多少天
答案:1 悬赏:60 手机版
解决时间 2021-06-02 03:27
- 提问者网友:wodetian
- 2021-06-01 04:38
越快越好
最佳答案
- 五星知识达人网友:孤独入客枕
- 2021-06-01 04:48
#include <iostream.h>
struct
{ int year;
int month;
int day;
}date;
int main()
{int days;
cout<<"input year,month,day:";
//char ch='\\';
cin>>date.year>>date.month>>date.day;
switch(date.month)
{ case 1: days=date.day; break;
case 2: days=date.day+31; break;
case 3: days=date.day+59; break;
case 4: days=date.day+90; break;
case 5: days=date.day+120; break;
case 6: days=date.day+151; break;
case 7: days=date.day+181; break;
case 8: days=date.day+212; break;
case 9: days=date.day+243; break;
case 10: days=date.day+273; break;
case 11: days=date.day+304; break;
case 12: days=date.day+334; break;
}
if ((date.year %4== 0 && date.year % 100 != 0
||date.year % 400 == 0) && date.month >=3)
days+=1;
cout<<date.month<<"/"<<date.day<<" is the "<<days
<<"th day in "<<date.year<<"."<<endl;
return 0;
}
struct
{ int year;
int month;
int day;
}date;
int main()
{int days;
cout<<"input year,month,day:";
//char ch='\\';
cin>>date.year>>date.month>>date.day;
switch(date.month)
{ case 1: days=date.day; break;
case 2: days=date.day+31; break;
case 3: days=date.day+59; break;
case 4: days=date.day+90; break;
case 5: days=date.day+120; break;
case 6: days=date.day+151; break;
case 7: days=date.day+181; break;
case 8: days=date.day+212; break;
case 9: days=date.day+243; break;
case 10: days=date.day+273; break;
case 11: days=date.day+304; break;
case 12: days=date.day+334; break;
}
if ((date.year %4== 0 && date.year % 100 != 0
||date.year % 400 == 0) && date.month >=3)
days+=1;
cout<<date.month<<"/"<<date.day<<" is the "<<days
<<"th day in "<<date.year<<"."<<endl;
return 0;
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯