#include <bits/stdc++.h>
struct date{
int month;
int day;
int year;
};
int numberofDays( struct date d);
bool isLeap(struct date d);
int numberofDays( struct date d){
int days;
const int daysPerMonth[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
//如果是闰年
if(d.month == 2 && isLeap(d))
days = 29;
else
//数组从0下标开始
days = daysPerMonth[d.month-1];
return days;
}
bool isLeap(struct date d){
bool leap = false;
if((d.year %4 == 0 && d.year % 100 != 0) || d.year % 400 == 0 )
leap = true;
return leap;
}
int main(){
struct date today,tomorrow;
printf("today date (mm dd yy):");
scanf("%d %d %d",&today.month,&today.day,&today.year);
//判断是不是这个月的最后一天
if( today.day != numberofDays(today)){
tomorrow.day = today.day + 1;
tomorrow.month = today.month;
tomorrow.year = today.year;
} else if(today.month == 12){
tomorrow.day = 1;
tomorrow.month = 1;
tomorrow.year = today.year + 1;
}else{
tomorrow.day = 1;
tomorrow.month = today.month - 1;
tomorrow.year = today.year;
}
printf("tomorrow date (mm dd yy):%d %d %d\n",tomorrow.month,tomorrow.day,tomorrow.year);
return 0;
}
确定明天的日期 C(结构体实现)
最新推荐文章于 2023-04-13 14:05:40 发布