给出年、月、日,计算该日是该年的第几天
代码如下
#include<bits/stdc++.h>
using namespace std;
int main()
{
int year,month,day,flag=0,s=0;
cout<<"请输入年份:";
cin>>year;
cout<<"请输入月份:";
cin>>month;
cout<<"请输入日期:";
cin>>day;
if((year%4 == 0&&year%100 !=0 || year%400 == 0))
flag=1;
for(int i=1;i<month;i++)
{
if(i == 1||i == 3||i == 5||i == 7|| i== 8|| i == 10|| i== 12)
{
s=s+31;
}
if(i == 4||i == 6|| i== 9||i == 11)
{
s=s+30;
}
if(i==2)
{
if(flag=1)
{
s=s+29;
}
else
{
s=s+28;
}
}
}
s=s+day;
cout<<"该日期是该年的第:"<<s<<"天"<<endl;
return 0;
}
(````````````````````````````````````````````````````````````````````````````````````)