//输入今天的日期年月日 输出明天的日期年月日 其中要判断闰年的年份来确定2月份最后一天
#include<stdio.h>
#include<stdbool.h>
struct date {
int month;
int day;
int year;
};
//运用两个函数isleap num
bool isleap(struct date d);//判断闰年 是返回true
int number(struct date d);
int main(int argc,char const*argv[]) {
struct date today, tomorrow;//定义两个变量
printf("enter today's date is (mm dd yyyy):");
scanf_s("%i %i %i", &today.month, &today.day, &today.year);//取点的地址来的高
//如果这一天不是本月最后一天day+1
if (today.day != number(today)) {
tomorrow.day = today.day + 1;
tomorrow.month = today.month;
tomorrow.year = today.year;
}
//年份加1
else if (today.month == 12) {
tomorrow.day = 1;
tomorrow.month = 1;
tomorrow.year = today.year + 1;
}
//月份加1
else {
tomorrow.day = 1;
tomorrow.month = today.month + 1;
tomorrow.year = today.year;
}
printf("tomorrom's date is %i-%i-%i\n",tomorrow.year, tomorrow.month, tomorrow.day);
return 0;
}
int number(struct date d)
{
int days;
const int monthd[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 30, 31 };//12个月
if (d.month == 2 && isleap(d))//是闰年
days = 29;
else
days = monthd[d.month - 1];//因为数组里第一位是0
return days;
}
bool isleap(struct date d)
{
bool leap = false;
//2008
if ((d.year % 4 == 0 && d.year % 100 != 0) || d.year % 400 == 0)
leap = true;
return leap;
}