- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int y,m,d,total=0,i;
- int db[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};
- cout<<"請輸入年月日並以空格分隔:";
- cin>>y>>m>>d;
- if((y%4==0&&y%100!=0)||(y%400==0))
- {
- cout<<y<<"年是閏年"<<endl;
- for(i=0;i<m-1;i++)
- {
- total+=db[1][i];
- }
- }else
- {
- cout<<y<<"年是平年"<<endl;
- for(i=0;i<m-1;i++)
- {
- total+=db[0][i];
- }
- }
- total+=d;
- cout<<"您輸入的日期"<<y<<"年"<<m<<"月"<<d<<"日,"<<"是這一年中的第"<<total<<"天\n";
- system("pause");
- return 0;
- }
複製代碼 |