作业帮 > 综合 > 作业

用C程序编一个程序,设今天是20世纪的某一天,用三位整数表示今天的年(year)月(month)日(day)……

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/17 02:03:46
用C程序编一个程序,设今天是20世纪的某一天,用三位整数表示今天的年(year)月(month)日(day)……
用C程序编一个程序,设今天是20世纪的某一天,用三位整数表示今天的年(year)月(month)日(day).请编写程序,输入今天的日期,计算并报告明天的日期.
#include
struct at_90s //定义日期结构
{
int year;
int month;
char day;
};
int isLeapYear(int year)//判断是否为闰年
{
if((year%400==0)|((year%100!=0)&(year%4==0)))
return 1;
return 0;
}
int getNextMd(int year,int month)//计算本月日期长度
{
int flag=isLeapYear(year);
if(flag&&(month==2))
return 29;
else
switch((month)%12)
{
case 0:return 31;
case 1:return 31;
case 2:return 28;
case 3:return 31;
case 4:return 30;
case 5:return 31;
case 6:return 30;
case 7:return 31;
case 8:return 31;
case 9:return 30;
case 10:return 31;
case 11:return 30;
}
}
void main()
{
struct at_90s test={1990,9,3
}; //初始化
printf("please enter a date(y-m-d):");
scanf("%d-%d-%d",&test.year,&test.month,&test.day);
printf("\ntoday is %d-%d-%d",test.year,test.month,test.day);
if((test.day)==getNextMd(test.year,test.month))//是本月最后一天月数加1
{
if(test.year==12)
test.year+=1;//是12月最后一天年数加1
test.month+=1;
test.day=1;
}
else
test.day+=1;
printf("\ntomorrow is %d-%d-%d",test.year,test.month,test.day);
getchar();
getchar();
}
纯人脑,非copy,