怎么用c语言编程一个分段函数?

Python030

怎么用c语言编程一个分段函数?,第1张

#include

int main()

{

int x,y

scanf("%d",&x)

if(0<x&&x<10) y=3*x+2

else

{if(x=0) y=0

else

{if (x<0) y=x*x

else printf("go die\n")

}

}

printf("%d",y)

return 0

}该程序的分段函数如下:

f(x)=3x+2  (0<x<10)

f(x)=1         (x=0)

f(x) = x*x    (x<0)

#include <stdio.h>

#include <math.h>

void main()

{

float x

double y

printf("Please input the value of x:")

scanf("%f",&x)

if(x>=-10&&x<=4)

{

y=fabs(x-2)

printf("y=%.2f\n",y)

}

else if(x>=5&&x<=7)

{

y=x+10

printf("y=%.2f\n",y)

}

else if(x>=8&&x<=12)

{

y=pow(x,4)

printf("y=%.2f\n",y)

}

else

printf("No answer\n")

}

#include <stdio.h>#include <math.h>void main() { float xdouble yprintf("Please input the value of x:")scanf("%f",&x)if(x>=-10&&x<=4) { y=fabs(x-2)printf("y=%.2f\n",y)} else if(x>=5&&x<=7) { y=x+10printf("y=%.2f\n",y)} else if(x>=8&&x<=12) { y=pow(x,4)printf("y=%.2f\n",y)} else printf("No answer\n")}

采纳哦