C语言初学者。。在线等答案

include <stdio.h>
int main()
{
double x;
int y;
scanf("%d",&x);
if(x>0)
y=1
else
{
if(x<0)
y=-1;
else y=0;
}
printf("%d\n",y);
return 0;
}
我不知道哪里错了。。。

include前忘了加#字号
y=1忘记加;
scanf("%d",&x);用%f
------------------------------------
#include<stdio.h>
#include<stdlib.h>
int main()
{
int x;
int y;
scanf("%f",&x);
if(x>0){
y=1;
}
else if(x<0){
y=-1;
}
else{
y=0;
}

printf("%d\n",y);
system("pause");
return 0;
}追问

逻辑上不知道哪里错了。。。。。我输入正数它输出的还是-1

追答

建议你用if,else if ,else
--------------------------
if(x>0){
y=1;
}
else if(x<0){
y=-1;
}
else{
y=0;
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-01-24
#include <stdio.h> //你的代码中,include 前面没有#号
int main()
{
double x;
int y;
scanf("%d",&x);
if(x>0)
y=1; //你的代码中,这里没有分号,就这里和上面两个错误
else
{
if(x<0)
y=-1;
else y=0;
}
printf("%d\n",y);
return 0;
}
//逻辑部分就不帮你看了,就帮你看了语法上的追问

逻辑上不知道哪里错了。。。

本回答被网友采纳
第2个回答  2013-01-24
scanf("%d",&x);

x的类型是double,不要用%d,用%f
或者把x定义成int
第3个回答  2013-01-24
把 scanf("%d",&x)改成 scanf("%f",&x),在y=1后面加个分号。
第4个回答  2013-01-24


double 或者 float的话,采用%d的话 可能输入为0哦,应采用%f

#inlucde <stdio.h> 你少了#号哦,亲

第5个回答  2013-01-24
if(x>0)
y=1   是不是这里少个分号啊
相似回答