float fun(float x)
{
float y;
if (x <= 1)
y = x;
else if (x > 1 && x <= 10)
y = 2 * x - 1;
else
y = 3 * x - 11;
return y;
}
供参考:
#include<stdio.h>
float fun(float x)
{
if(x<=1) return x;
if(x>1 && x<10) return (2*x-1);
if(x >= 10) return (3*x-11);
}
void main()
{
float x;
printf("输入数x:\n");
scanf("%f",&x);
printf("y=%f\n",fun(x));
}