[cpp] #include <iostream> using namespace std; struct Date { int year; int month; int day; }; int days(Date date); int main() { int xc; Date date1,date2; cout<<"input 第一位同學出生 year,month,day:"; cin>>date1.year>>date1.month>>date1.day; cout<<"input 第二位同學出生 year,month,day:"; cin>>date2.year>>date2.month>>date2.day; int days1,days2; days1=days(date1); days2=days(date2); xc=days1-days2; if(xc<0) xc=-xc; cout<<"兩人生日相差"<<xc<<"天"<<endl; return 0; } int days(Date date) { int days; switch(date.month) { case 1: days=date.day; break; case 2: days=date.day+31; break; case 3: days=date.day+59; break; case 4: days=date.day+90; break; case 5: days=date.day+120; break; case 6: days=date.day+151; break; case 7: days=date.day+181; break; case 8: days=date.day+212; break; case 9: days=date.day+243; break; case 10: days=date.day+273; break; case 11: days=date.day+304; break; case 12: days=date.day+334; break; } if(date.year%4==0 && date.year/100==0 || date.year%400==0) date.day+=1; return days; }