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函数。刚自学,想了很久还是不会。 展开
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函数。刚自学,想了很久还是不会。 展开
展开全部
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") ;
}
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") ;
}
追问
就是哦,太本老我。 这个就没有想到。非常感谢、。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询