① 怎么用c语言编程一个分段函数
#include
intmain()
{
intx,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;
elseprintf("godie
");
}
}
printf("%d",y);
return0;
}该程序的分段函数如下:
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
",y);
}
else if(x>=5&&x<=7)
{
y=x+10;
printf("y=%.2f
",y);
}
else if(x>=8&&x<=12)
{
y=pow(x,4);
printf("y=%.2f
",y);
}
else
printf("No answer
");
}