有一函数: 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 的值。
展开
 我来答
歧轩V1
2016-08-03
知道答主
回答量:2
采纳率:0%
帮助的人:2115
展开全部
#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");
}
coclely
2013-04-29 · TA获得超过262个赞
知道小有建树答主
回答量:227
采纳率:100%
帮助的人:183万
展开全部
你题目有问题吧。 正常题目应该是
当(-5<x<0) 时 y=x
当(x=0) y=x-1
当(0<x<10) y=x+1
这样才正常嘛。。。。。
基本题目,要好好听课啊。。。都没什么好想的。按这个逻辑写代码就完了。
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式