@C语言大神:这里我用了&&来分段,怎么还是全部都输出来了?求解释!
# include
# include
int main()
{
long int x;
long int place,ts,thousand,hundred,ten,indiv;
printf("please input a number: ");
scanf("%d",&x);
if(x>99999)
{printf("wrong. ");}
else if(x>=10000&&x=1000&&x=100&&x=10&&x<=99)
{
place=2;
thousand=x/1000;
hundred=(x-1000*thousand)/100;
ten=(x-1000*thousand-100*hundred)/10;
indiv=(x-1000*thousand-100*hundred-10*ten);
}
else
{
place=1;
}
switch(place)
{
case 5:printf("place is 5 ");
printf("the numberi is %d%d%d%d%d ",ts,thousand,hundred,ten,indiv);
printf("the resverse is %d%d%d%d%d ",indiv,ten,hundred,thousand,ts);
//以此类推
}
getch();
}
楼主的switch是不是缺少了break语句呀
123456789switch(place){case 5:printf("place is 5 "); printf("the numberi is %d%d%d%d%d ",ts,thousand,hundred,ten,indiv); printf("the resverse is %d%d%d%d%d ",indiv,ten,hundred,thousand,ts); break; //这里是不是少了breakcase 4://以此类推}
switch语句只是找到case的匹配条件之后,然后就会顺序往下执行。
一直执行到switch语句的末尾或者碰见break语句才结束。
即,如果走进了case 5的分支,case 5结束后,如果没有break,就会继续执行case 4和后面的语句了。
问:c 语言 如何编写 * ** *** **** ***** ****** 这个输出?
答:#include using namespace std; int main(){ for (i=1;i<=6;i++){ for(j=1;j<=i;j++) ...详情>>