这段代码可以编译成功但是结果不对,有朋友帮看看哪里有问题吗?

#include <stdio.h>
int main()
{int x;
int y;
int a=x+1;
int b=0;
int c=x-1;
printf("请输入x=");
scanf("%d",&x);
if(x<0)
{printf("y=%d",a);}
else
if(x==0)
{printf("y=%d",b);}
else
{printf("y=%d",c);}
return 0;
}

#include <stdio.h>
int main()
{int x=0;
printf("请输入x=");
scanf("%d",&x);
int y;
int a=x+1;
int b=0;
int c=x-1;
if(x<0)
{
printf("y=%d",a);
}
else if(x==0)

{
 printf("y=%d",b);
}
else
{
printf("y=%d",c);
}

return 0;
}

int x;
int y;
printf("请输入x=");
scanf("%d",&x);
int a=x+1;
int b=0;
int c=x-1;

你的a,b,c的运算中使用的x未在运算前赋值所以它在运算时是一个任意值,所以你为x赋值的那段要放在他们前面