用C语言编写一个程序:输入今天的日期,输出明天的日期,请问我的设计错在哪了?
#include<stdio.h>intmain(){inty,m,d;printf("ÇëÊäÈëÄ...
#include <stdio.h>
int main()
{
int y,m,d;
printf("ÇëÊäÈëÄêÔÂÈÕ£¬ÖмäÓöººÅ¸ô¿ª£¡\n");
scanf ("%d,&d,%d",&y,&m,&d);
switch (m)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:if(d>0&&d<=30)
d=d+1;
else m=m+1;
d=1;
break;
case 12:if(d>0&&d<=30)
d=d+1;
else m=1;
d=1;
y=y+1;
break;
case 4:
case 6:
case 9:
case 11:if(d>0&&d<=29)
d=d+1;
else m=m=1;
d=1;
break;
case 2:if(y%4==0&&y%100!=0||y%400==0)
{
if(d>0&&d<=28)
d=d+1;
else m=3;
d=1;
}
else
{if(d>0&&d<=27)
d=d+1;
else
m=3;
d=1;
}
break;
}
printf("Ã÷ÌìµÄÈÕÆÚÊÇ%dÄê%dÔÂ%dÌì\n",y,m,d);
} 展开
int main()
{
int y,m,d;
printf("ÇëÊäÈëÄêÔÂÈÕ£¬ÖмäÓöººÅ¸ô¿ª£¡\n");
scanf ("%d,&d,%d",&y,&m,&d);
switch (m)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:if(d>0&&d<=30)
d=d+1;
else m=m+1;
d=1;
break;
case 12:if(d>0&&d<=30)
d=d+1;
else m=1;
d=1;
y=y+1;
break;
case 4:
case 6:
case 9:
case 11:if(d>0&&d<=29)
d=d+1;
else m=m=1;
d=1;
break;
case 2:if(y%4==0&&y%100!=0||y%400==0)
{
if(d>0&&d<=28)
d=d+1;
else m=3;
d=1;
}
else
{if(d>0&&d<=27)
d=d+1;
else
m=3;
d=1;
}
break;
}
printf("Ã÷ÌìµÄÈÕÆÚÊÇ%dÄê%dÔÂ%dÌì\n",y,m,d);
} 展开
3个回答
展开全部
#include <stdio.h>int main(){ int year,month,day; int maxdays[]={31,28,31,30,31,30,31,31,30,31,30,31}; printf("请输入年月日,中间用空格隔开!\n"); scanf("%d %d %d",&year,&month,&day); if(year%400==0 || (year%4==0 && year%100!=0)) maxdays[1]=29;//闰年二月最大值是29 if(month>12 || month<1) { printf("日期不合法!\n"); return 0; } if(day>maxdays[month-1]) { printf("日期不合法!\n"); return 0; } day++; if(day>maxdays[month-1]) { day=1; month++; if(month>12) { month=1; year++; } } printf("明天的日期是:%d-%d-%d\n",year,month,day); return 0;}
展开全部
#include <stdio.h>
int main()
{
int y,m,d;
printf("请输入年月日,中间用逗号隔开!\n");
scanf ("%d,%d,%d",&y,&m,&d); /*这地方打错一个%*/
switch (m)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:if(d>0&&d<=30)
d=d+1;
else
{ m=m+1;
d=1;} /*这地方补一对花括号*/
break;
case 12:if(d>0&&d<=30)
d=d+1;
else
{m=1;
d=1;
y=y+1;} /*这地方补一对花括号*/
break;
case 4:
case 6:
case 9:
case 11:if(d>0&&d<=29)
d=d+1;
else { m=m+1; /*这地方改为+号 */
d=1;} /*这地方补一对花括号 */
break;
case 2:if(y%4==0&&y%100!=0||y%400==0)
{
if(d>0&&d<=28)
d=d+1;
else
{ m=3;
d=1;} /*这地方补一对花括号*/
}
else
{if(d>0&&d<=27)
d=d+1;
else
{
m=3;
d=1;} /*这地方补一对花括号*/
}
break;
}
printf("明天的期是%d年%d月%d日\n",y,m,d);
getch();
}
int main()
{
int y,m,d;
printf("请输入年月日,中间用逗号隔开!\n");
scanf ("%d,%d,%d",&y,&m,&d); /*这地方打错一个%*/
switch (m)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:if(d>0&&d<=30)
d=d+1;
else
{ m=m+1;
d=1;} /*这地方补一对花括号*/
break;
case 12:if(d>0&&d<=30)
d=d+1;
else
{m=1;
d=1;
y=y+1;} /*这地方补一对花括号*/
break;
case 4:
case 6:
case 9:
case 11:if(d>0&&d<=29)
d=d+1;
else { m=m+1; /*这地方改为+号 */
d=1;} /*这地方补一对花括号 */
break;
case 2:if(y%4==0&&y%100!=0||y%400==0)
{
if(d>0&&d<=28)
d=d+1;
else
{ m=3;
d=1;} /*这地方补一对花括号*/
}
else
{if(d>0&&d<=27)
d=d+1;
else
{
m=3;
d=1;} /*这地方补一对花括号*/
}
break;
}
printf("明天的期是%d年%d月%d日\n",y,m,d);
getch();
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
IF后面的语句体如果有多条语句,要用{}括起来.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询