c语言中有关if的问题。

#include<stdio.h>intmain(void){intmouth,day;printf("pleaseinputthemouthwhichyouwantto... #include <stdio.h>
int main (void)
{
int mouth , day ;
printf ("please input the mouth which you want to know :") ;
scanf ("%d",&mouth );
if ( mouth == 1||mouth == 3 || mouth == 7 ||mouth == 8 || mouth == 10|| mouth ==12 )
{
day =31;
printf ("2013.%d have %d\n",mouth ,day) ;
}
else
if (mouth == 4 || mouth == 6 ||mouth == 9 || mouth == 11)
{
day = 30 ;
printf ("2013.%d have %d\n",mouth ,day) ;
}
else
if ( mouth == 2 )
{
day = 28 ;
printf ("2013.%d have %d\n",mouth ,day) ;
}
else
{
printf ("error!\n") ;
}
return 0 ;
}
这个代码怎么改才不会每个If语句中都用到printf函数。刚自学,想了很久还是不会。
展开
 我来答
zjfaok
2013-03-16 · TA获得超过6806个赞
知道大有可为答主
回答量:4146
采纳率:62%
帮助的人:1619万
展开全部
if ( mouth>0 && mouth<13){
if ( mouth == 1||mouth == 3 || mouth == 7 ||mouth == 8 || mouth == 10|| mouth ==12 )day =31;
else if (mouth == 4 || mouth == 6 ||mouth == 9 || mouth == 11)day = 30 ;
else if ( mouth == 2 ) day = 28 ;
printf ("2013.%d have %d\n",mouth ,day) ;
}else{
printf ("error!\n") ;
}
追问
就是哦,太本老我。 这个就没有想到。非常感谢、。
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式