程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> C++編程,求你自己活了多少天

C++編程,求你自己活了多少天

編輯:C++入門知識

[cpp]
/*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;     

/*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;   
}


 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved