#include<iostream>
using namespace std;
struct Date
{
int year;
int month;
int day;
};
bool run(int);
int days(Date &);
int main()
{
cout<<"请输入你要计算的日期:\n";
Date date;
cout<<"年:";
cin>>date.year;
cout<<"月:";
cin>>date.month;
cout<<"日:";
cin>>date.day;
cout<<date.year<<"年"<<date.month<<"月"<<date.day<<"日是这一年的第"
<<days(date)<<"天\n";
system("pause");
return 0;
}
bool run(int ra)
{
if(ra%4==0&&ra%100!=0||ra%400==0)
return 1;
else
return 0;
}
int days(Date & date)
{
int yue[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int x,sum=0;
for(x=1;x<date.month;x++)
sum=sum+yue[x];
if(run(date.year)&&date.month>=3)
sum++;
return sum+date.day;
}
参考资料:C++