The difference between their birthdays

Source: Internet
Author: User

Enter the code:

/**copyright (c) 2014, College of Computer and Control engineering, Yantai University *all rights reserved.* file name: sum123.cpp* Author: Lin Haiyun * Completion date: December 23, 2014 * Version number: v2.0** Problem Description: Enter two people's birthday, ask for the difference in days * Program input: * Program output: */#include <iostream> #include <cmath>using namespace Std;int day (int y,int    M,int d); struct date{int year;    int mouth; int day;};    int main () {Date date1,date2;    int sum1,sum2,s=0;    cout<< "Please enter the first person's birthday:" <<endl;    cin>>date1.year>>date1.mouth>>date1.day;    cout<< "Please enter a second person's birthday:" <<endl;    cin>>date2.year>>date2.mouth>>date2.day;    Sum1=day (Date1.year,date1.mouth,date1.day);    Sum2=day (Date2.year,date2.mouth,date2.day);            if (date1.year>date2.year) {while (date1.year>=date2.year) {date1.year--; if ((date1.year%4==0) && (date1.year%100!=0) | |            (date1.year%400==0))            {s+=366;            } else s+=365;        date1.year--;        } sum1+=s;  sum1-=sum2;      cout<< "Two people's birthday difference is:" <<sum1<<endl;            } else if (Date1.year<date2.year) {while (date2.year>=date1.year) {date2.year--; if ((date2.year%4==0) && (date2.year%100!=0) | |            (date2.year%400==0))            {s+=366;            } else s+=365;        date2.year--;        } sum2+=s;        SUM2-=SUM1;    cout<< "Two people birthday difference:" <<sum2<<endl;    } else cout<< "The difference between birthdays for two" <<fabs (sum1-sum2) <<endl; return 0;}    int day (int y,int m,int d) {int sum=0,i; for (I=1; i<=m; i++) {if (i==1| | i==3| | i==5| | i==7| | i==8| |i==10| |        I==12) sum+=31; else if (i==4| | i==6| | i==9| |        i==11) sum+=30; else {if (y%4==0 && (y%100!=0) | |                (y%400==0))            sum+=29;        else sum+=28;    }} Sum+=d; return sum;}


Operation Result:

The difference between their birthdays

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.