有一函数: x (-5<x<0) y= x-1 (x=0) x+1 (0<x<10) 分别用: (1)简单if 语句 (
5-21.有一函数:x(-5<x<0)y=x-1(x=0)x+1(0<x<10)分别用:(1)简单if语句(2)嵌套的if语句(3)if-else语句(4)switch语...
5-21.有一函数:
x (-5<x<0)
y= x-1 (x=0)
x+1
(0<x<10)
分别用: (1)简单if 语句 (2)嵌套的if 语句
(3)if-else语句 (4)switch
语句
编写程序,要求输入x 的值,输出y 的值。 展开
x (-5<x<0)
y= x-1 (x=0)
x+1
(0<x<10)
分别用: (1)简单if 语句 (2)嵌套的if 语句
(3)if-else语句 (4)switch
语句
编写程序,要求输入x 的值,输出y 的值。 展开
2个回答
展开全部
#include <stdio.h>
main()
{
int x,y;
printf("input x :");
scanf("%d",&x);
printf("*****************************************************************\n");
if(x>-5&&x<0)
printf(" y1=%d \n",x);
if(x==0)
printf("y1=%d \n",x-1);
if(x>0&&x<10)
printf ("y1=%d \n",x+1);
if(x>10||x<-5)
printf("y1输入错误!\n");
printf("*****************************************************************\n");
if(x!=0)
{
if(x<-5||x>0)
{
if(x<10&&x>0)
{
printf ("y2=%d \n",x+1);
}
else
printf("y2输入错误!\n");
}
else
printf(" y2=%d \n",x);
}
else
printf("y2=%d \n",x-1);
printf("*****************************************************************\n");
if(x>-5&&x<0)
printf(" y3=%d \n",x);
else if(x==0)
printf("y3=%d \n",x-1);
else if(x>0&&x<10)
printf ("y3=%d \n",x+1);
else
printf("y3输入错误!\n");
printf("*****************************************************************\n");
int n;
if(x>-5&&x<0)
n=1;
if(x==0)
n=2;
if(x>0&&x<10)
n=3;
if(x>10||x<-5)
n=4;
switch(n)
{
case 1: printf(" y4=%d \n",x);break;
case 2: printf("y4=%d \n",x-1);break;
case 3: printf ("y4=%d \n",x+1);break;
case 4: printf("y4输入错误!\n");break;
}
printf("*****************************************************************\n");
}
main()
{
int x,y;
printf("input x :");
scanf("%d",&x);
printf("*****************************************************************\n");
if(x>-5&&x<0)
printf(" y1=%d \n",x);
if(x==0)
printf("y1=%d \n",x-1);
if(x>0&&x<10)
printf ("y1=%d \n",x+1);
if(x>10||x<-5)
printf("y1输入错误!\n");
printf("*****************************************************************\n");
if(x!=0)
{
if(x<-5||x>0)
{
if(x<10&&x>0)
{
printf ("y2=%d \n",x+1);
}
else
printf("y2输入错误!\n");
}
else
printf(" y2=%d \n",x);
}
else
printf("y2=%d \n",x-1);
printf("*****************************************************************\n");
if(x>-5&&x<0)
printf(" y3=%d \n",x);
else if(x==0)
printf("y3=%d \n",x-1);
else if(x>0&&x<10)
printf ("y3=%d \n",x+1);
else
printf("y3输入错误!\n");
printf("*****************************************************************\n");
int n;
if(x>-5&&x<0)
n=1;
if(x==0)
n=2;
if(x>0&&x<10)
n=3;
if(x>10||x<-5)
n=4;
switch(n)
{
case 1: printf(" y4=%d \n",x);break;
case 2: printf("y4=%d \n",x-1);break;
case 3: printf ("y4=%d \n",x+1);break;
case 4: printf("y4输入错误!\n");break;
}
printf("*****************************************************************\n");
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询