供参考:
#include <stdio.h>
#include <math.h>
int main()
{
double x, y;
scanf("%lf", &x);
if (x < 1 || x >= 5)
printf("No define!");
else {
if (x >= 1 && x < 2)
y = 3 * x + 5;
else if (x >= 2 && x < 3)
y = 2 * sin(x) - 1;
else if (x >= 3 && x < 4)
y = sqrt(1 + x * x);
else if (x >= 4 && x < 5)
y = x * x - 2 * x + 5;
printf("%.2f", y);
}
return 0;
}
你的函数部分会写,那就基本写好了呀,至于超出范围,显示no define的意识就是判断x的值,x的范围不是1到5吗,只要x不在这个范围内就输出no define即可。大概代码是这样的,你修改下就可以:
if x>=1 and x <2
y = 3*x+5
else if x>=2 and x <3
y = 2*math.sin(x)-1
else if x>=3 and x <4
y = 2*math.sqrt(1+x*x)
else if x>=4 and x <5
y =x*x -2*x+5
else
printf('No define!')
其中的sin函数和开根号函数不一定是这个方法哈,我是用的python语言。大概逻辑就是这样,你改成C语言的就行了。望采纳哦!!!!