创意转角电视柜墙角柜:一个C语言编程题?

来源:百度文库 编辑:神马品牌网 时间:2024/04/26 17:44:18
有一个函数 x (-5<x<0)

Y= x-1 (x=0)

x+1 (0<x<10)

编写一个程序,要求输入一个x的值,输出y的值,分别用;
(1)if else 语句 (2)switch 语句
如果不用嵌套可以吗?
只用if else 结构.
还有switch结构?

以下是正确的程序.但有谁 能为我编一个switch结构的.

还有编一个只有if-else结构的程序,不能用有嵌套.

main()
{float x,y;
printf("please enter x:");
scanf("%f",&x);
if (x>-5&&x<0) printf("y=%f",x);
else if(x==0) printf("y=%f",x-1);
else if(x>0&&x<10) printf("y=%f", x+1);
else printf("wrong!");

}

(1)
main()
{int x,y;
printf("please enter x:");
csanf("%d",&x);
if (x>(-5)&&x<0) y=x;
else if(x==0) y=x-1;
else if(x>0&&x<10) y=x+1;
else printf("wrong!");
printf("y=%d",y);
}

PS:用&&是对的, &&是"与"的意思,||是“或”的意思。应该是“与”。

呵,,我是旁人.,但是也想学C,,你能讲解一下吗...或者...留下你的QQ
!

我向你学习好吗?

#include"stdio"
main()
{int x,y;
printf("please enter x:\n");
scanf("%f,&x");
if(-5<x||x<0) y=x;
else if (x==0) y=x-1;
else if (0<x<10) y=x+1;
else printf("wrong!");
printf("y=%f,y"):
}

你编译一下试试吧,好久不用了,有点生:)

ps:楼上的程序有好多错,没有输入x,&&也不对

只能改错了
scanff("%f",&x);引号
printf("y=%f",y);