怎么编一个程序可以准确计算某年某月某日是某年的第几天? 谢谢~
估计是要做作业挂~~~
简单点的``初学者估计比较容易看懂```仅供参考``
不足之处还需提出改进```
#include <iostream>
using namespace std;
bool Isleap(int y)
{
return y%4==0 && y%100!=0 || y%400==0;
}
int Dom(int y , int m )
{
int d ;
if(m==2)
{
if(Isleap(y))
d = 29;
else
d = 28;
}
else if(m%2==1 && m<=7 || m%2==0 && m>=8)
d = 31;
else
d = 30 ;
return d;
}
int coutday(int y , int m , int d)
{
int day=0,i;
for(i=1;i<m;i++)
day = day + Dom(y , i);
day = day + d;
return day;
}
int main()
{
int year , month , day;
cout<<"please input year , month , day:"<<endl;
cin>>year>>month>>day;
cout<<"the reason is"<<coutday(year,month,day)<<endl;
return 0;
}