#include
void main()
{
int x,k;
scanf("%d",&x);
if(x<0&&x>-5) k=-1;
else if (x=0) k=0;
else if(x>0&&x<10) k=1;
switch(k)
{
case -1: printf("y=%d",x); break;
case 0: printf("y=%d",0); break;
case 1: printf("y=%d",x+1); break;
}
}
/*使用if嵌套语句*/
#include
void main()
{
int x;
scanf("%d",&x);
if(x>-5&&x<0) y=x;
else if(x==0) y=x-1;
else y=x+1;
printf("%d\n",y);
}
/*使用switch语句*/
#include
void main()
{
int x,choice;
do
{
scanf("%d",&x);
}while(x<-5||x>10);
if(x<0) choice=1;
if(x==0) choice=0;
if(x>0) choice=2;
switch(choice)
{
case 0:y=x-1;break;
case 1:y=x;break;
case 2:y=x+1;brea;
}
printf("%d\n",y);
}
#include
int main()
{
int x,y;
scanf("%d",&x);
if((x>(-5))&&(x<0))
{
y=x;
printf("%d",y);
}
else
if(x==0)
{
y=x-1;
printf("%d",y);
}
else
if((x>0)&&(x<10))
{
y=x+1;
printf("%d",y);
}
else
printf("The input is error!");
return 0;
}
if版:
#include
#include
int main(int argc, char *argv[])
{
int x,y;
scanf("%d",&x);
if(-5
}
else if(x==0){
y=x-1;
}
else if(0
}
printf("%d",y);
return 0;
}
**********************
switch版:
#include
#include
int main(int argc, char *argv[])
{
int x,y;
scanf("%d",&x);
switch(x){
case -4:
case -3:
case -2:
case -1:
y=x;
break;
case 0:
y=x-1;
break;
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
y=x+1;
break;
default:
break;
}
printf("%d\n",y);
return 0;
}
#include
main(){double x,y;
printf("请输入x的值");
scantf(”%lf“,&x)
if(x<0&&x>-5)y=x;
else if(x==0) y=x-1;
else if (x<10&&x>0) y=x+1;
else;
printf("%lf",y);}