题目要求用C语言编写一个程序:输入今天的日期,输出明天的日期,请问我的设计错在哪了?
#include<stdio.h>intmain(){intyear,month,days;printf("Pleaseinputyourdata:\n");scanf(...
#include <stdio.h>
int main()
{
int year,month,days;
printf("Please input your data:\n");
scanf("%d,%d,%d",&year,&month,&days);
switch(month)
{
case1:
case3:
case5:
case7:
case8:
case10:
if(days<=31&&days>=0)
{
days++;
month=month;
year=year;
}
if(days=31)
{
days=1;
month++;
year=year;
}
printf("%d,%d,%d\n",year,month,days);break;
case4:
case6:
case9:
case11:
if(days<=30&&days>=0)
{
days++;
month=month;
year=year;
}
if(days=30)
{
days=1;
month++;
year=year;
}
printf("%d,%d,%d\n",year,month,days);break;
case2:
if(year%400==0||year%4==0&&year%100!=0)
{
if(days<=29&&days>=0)
{
days++;
month=month;
year=year;
}
if(days=29)
{
days=1;
month++;
year=year;
}
}
if(year%400!=0||year%4!=0)
{
if(days<=29&&days>=0)
{
days++;
month=month;
year=year;
}
if(days=29)
{
days=1;
month++;
year=year;
}
}
printf("%d,%d,%d\n",year,month,days);break;
case12:
if(days<=31&&days>=0)
{
days=days+1;
month=month;
year=year;
}
if(days=31)
{
days=1;
month=1;
year++;
}
printf("%d,%d,%d\n",year,month,days);break;
default:
printf("data error!");
}
printf("%d,%d,%d\n",year,month,days);
return 0;
} 展开
int main()
{
int year,month,days;
printf("Please input your data:\n");
scanf("%d,%d,%d",&year,&month,&days);
switch(month)
{
case1:
case3:
case5:
case7:
case8:
case10:
if(days<=31&&days>=0)
{
days++;
month=month;
year=year;
}
if(days=31)
{
days=1;
month++;
year=year;
}
printf("%d,%d,%d\n",year,month,days);break;
case4:
case6:
case9:
case11:
if(days<=30&&days>=0)
{
days++;
month=month;
year=year;
}
if(days=30)
{
days=1;
month++;
year=year;
}
printf("%d,%d,%d\n",year,month,days);break;
case2:
if(year%400==0||year%4==0&&year%100!=0)
{
if(days<=29&&days>=0)
{
days++;
month=month;
year=year;
}
if(days=29)
{
days=1;
month++;
year=year;
}
}
if(year%400!=0||year%4!=0)
{
if(days<=29&&days>=0)
{
days++;
month=month;
year=year;
}
if(days=29)
{
days=1;
month++;
year=year;
}
}
printf("%d,%d,%d\n",year,month,days);break;
case12:
if(days<=31&&days>=0)
{
days=days+1;
month=month;
year=year;
}
if(days=31)
{
days=1;
month=1;
year++;
}
printf("%d,%d,%d\n",year,month,days);break;
default:
printf("data error!");
}
printf("%d,%d,%d\n",year,month,days);
return 0;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询