/*C++编程,求你自己活了多少天*/ #include<iostream> using namespace std; int main(){ int y1,y2,m1,m2,d1,d2; int panduan(int y,int m,int d); double total=0; cout<<"please input your birthday:"; cin>>y1>>m1>>d1; cout<<y1<<"/"<<m1<<"/"<<d1<<endl; cout<<"please input now day date:"; cin>>y2>>m2>>d2; cout<<y2<<"/"<<m2<<"/"<<d2<<endl; for(int i=y1;i<y2;i++){ if((i%4==0&&i%100!=0)||(i%400==0))total+=366; else total+=365; } int duo1,duo2; duo1=panduan(y1,m1,d1); duo2=panduan(y2,m2,d2); total+=duo2-duo1; cout<<"you have lived for "<<total<<" days"<<endl; return 1; } int panduan(int y ,int m,int d){ 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}}; int duo=0,i=0; if((y%4==0&&y%100!=0)||(y%400==0)) { for(i=0;i<m-1;i++) { duo+=db[1][i]; } }else { for(i=0;i<m-1;i++) { duo+=db[0][i]; } } cout<<(duo+=d)<<endl; return duo; }
作者:QianShouYuZhiBo 发表于2013-6-7 0:44:49 原文链接
阅读:132 评论:2 查看评论