给出年、月、日,计算该日是该年的第几天
解答:
唯一需要注意的就是2月是多少天,闰年的公式为 能够被4和400整除,但是不能被100整除。
int dateSum() { int sum=0; int year,month,day; cout<<"请输入年月日: "; cin>>year>>month>>day; int a[12]={31,0,31,30,31,30,31,31,30,31,30,31}; int ly=lead(year); if (ly) { a[1]=29; }else a[1]=28; for (int i=0;i<month-1;i++) { sum += a[i]; } sum += day; cout<<"you data sum is :"<<sum<<endl; return sum; }