c语言问题 有一个分段函数y=x-1(x<0),0(x=0),x+1(x>0). 怎么编程?

输入1输出2输入12输出23输入012输出023.
2025-01-01 19:50:02
推荐回答(1个)
回答1:

y=x-1(x<0),0(x=0),x+1(x>0)
main()
{
int x,y;
scanf("%d",&x);
if(x==0)y=0;
if(x>0)y=x+1;
if(x<0)y=x-1;
printf("%d",y);
}