#include<>
#include<>
void main()
{
int year,month,day;
void nextdate(int ,int ,int );
printf("请输入年份(范围在1912-2050之间):");scanf("%d",&year);
printf("请输入月份(范围在1-12之间):");scanf("%d",&month);
printf("请输入日期(范围在1-31之间):");scanf("%d",&day);
printf("%d年%d月%d日的下一天是:",year,month,day);
nextdate(year,month,day);
}
void nextdate(int year,int month,int day)
{
int leap( int );
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
if(day>=1&&day<31)
day=day+1;
else if(day==31){
day=1;
month=month+1;
}
else
printf("输入数据错误!\n");
break;
case 12:
if(day>=1&&day<31)
day=day+1;
else if(day==31){
day=1;
month=1;
year=year+1;
}
else
{
printf("输入数据错误!\n");
exit(0);
}
break;
case 4:
case 6:
case 9:
case 11:
if(day>=1&&day<30)
day=day+1;
else if(day==30){
day=1;
month=month+1;
}
else
{
函数printf printf("输入数据错误!\n");
exit(0);
}
break;
case 2:
if(day>=1&&day<28)
day=day+1;
else if(!leap(year)&&day==28){
day=1;
month=month+1;
}
else if(leap(year)&&day==28)
day=day+1;
else if(leap(year)&&day==29){
day=1;
month=month+1;
}
else
{
printf("输入数据错误!\n");
exit(0);
}
}
printf("%d年%d月%d日\n",year,month,day);
}
int leap(int yy)
{
return (yy%400==0||(yy%4==0&&yy%100!=0));
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论