#include <iostream>
using namespace std;
struct Date
{
int year;
int month;
int day;
};
int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int main()
{
Date date;
cout<<"input year,month,day:";
cin>>date.year>>date.month>>date.day;
int days=0,i;
for(i=1;i<date.month;++i)//之所以用++i而不用i++是因为用++i当月份怎加到输入月份时就不成立,从而
days+=d[i];//使这一句只计算输入月之前月份的天数之和,避免了把输入月的天数加上
days+=date.day;
if((date.year%4==0&&date.year%100!=0||date.year%400==0)&&date.month>=3)
days+=1;
cout<<date.month<<"月"<<date.day<<"日是"<<date.year<<"年的第"<<days<<"天。"<<endl;
return 0;
}
/*有一个警告||=== 生成: Debug in 524 (compiler: GNU GCC Compiler) ===|
D:\work\524\main.cpp||In function 'int main()':|
D:\work\524\main.cpp|19|warning: suggest parentheses around '&&' within '||' [-Wparentheses]|
||=== Build finished: 0 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|
||=== 运行: Debug in 524 (compiler: GNU GCC Compiler) ===|*/
第七章回顾3.2
最新推荐文章于 2023-06-19 15:19:55 发布