用C语言编写 求分段函数的值

求分段函数的值
2x+3 x<0
y= 1 x=0
3x-5 x>0

第1个回答  2013-11-29
#include <stdio.h>void fun( float x);void main(){ fun(0); fun(-8); fun(9);}void fun(float x){ if(x==0) printf("y=1\n"); else if(x<0) printf("y=%f\n",2*x+3); else printf("y=%f\n",3*x-5);}
第2个回答  2013-11-29
#include<stdio.h>int x,a;int print(int a) { if(a< 0) return 2*a + 3; else if ( a== 0) return 1; else return 3*a- 5; return 1; }void main(){printf("please input x:");scanf("%d",&x);printf("函数的值为:%d",print(x));}
第3个回答  2013-11-29
#include<stdio.h>void main(){ double x,y; scanf("%lf",&x); if(x<0) y=2*x+3; else if(x>0) y=3*x-5; else y=1; printf("%lf\n",y);}
第4个回答  2013-11-29
int caluValue(int nX){ if(x < 0) return 2*nX + 3; else if ( x == 0) return 1; else return 3*x - 5; return 1;}