专业有线话筒:编写一个程序,

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/19 12:18:43
有一个函数 y=x(-5<x<0) y=x-1(x=0) y=x+1(0<x<10)
要求输入x的值,输出y的值.
分别用(1)不嵌套的if语句 (2)嵌套的if语句 (3)if_else语句

if x>-5 and x<0 then y=x
if x=0 then y=x-1
if x>0 and x<10 then y=x+1

if x>-5 and x<10 then
if x<0 then y=x
if x=0 then y=x-1
if x>0 then y=x+1
end if

if x>-5 and x<0 then
y=x
elseif x=0 then
y=x-1
elseif x>0 and x<10 then
y=x+1
end if

(1)(2)我看不出这函数能循环啊,有高手教教偶啊。

(3) main()
{
int x ,y;
scanf("%d",&x);
if(-5<x<0) ;y=x;printf("y=%d",y);
else if(x=0);y=x-1;printf("y=%d",y);
else if(0<x<10);y=x+1;printf("y=%d",y);
}
本人初学编程,有错请大家指出哈