#include <stdio.h>
#include <stdlib.h>
//输入今天的日期,求明天的日期
//
struct date{
int year;
int month;
int day;
};
bool isLeap(struct date d);
int numberOfDays(struct date d);
int main(int argc,char const *argv[])
{
struct date today,tomorrow;
printf("Enter today's date (mm dd yyyy):\n");
scanf("%i %i %i",&today.month,&today.day,&today.year);
//下面的是核心部分if ,else if, else
if(today.day!=numberOfDays(today)){//如果不是每月的最后一天,天加一,月不变,年不变
tomorrow.day=today.day+1;
tomorrow.month=today.month;
tomorrow.year=today.year;
}else if(today.month==12){//如果是12月最后一天的话,则要跨年
tomorrow.day=1;
tomorrow.month=1;
tomorrow.year=today.year+1;
}else{//如果是每月的最后一天(除12月),则年不变,月加一,天变一
tomorrow.day=1;
tomorrow.month=today.month+1;
tomorrow.year=today.year;
}
printf("Tomorrow's date is %i-%i-%i.\n",tomorrow.year,tomorrow.month,tomorrow.day);
return 0;
}
int numberOfDays(struct date d){
int days;
const int daysPerMonth[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
if(d.month==2&&isLeap(d)){//如果是闰年的2月,则2月有29天,否则,取月对应的天数
days=29;
}else{//否则的话,正常取对应月所对应的天数
days=daysPerMonth[d.month];
}
return days;
}
bool isLeap(struct date d){//判断是否为闰年,即能被4整除但不能被100整除,或者可以被400整除的数,就是闰年
bool leap=false;
if((d.year%4==0&&d.year%100!=0)||d.year%400==0){
leap=true;
}
return leap;
}