编写程序,根据从键盘输入的x值求解函数f(x)的结果。(要求用函数调用完成)
用if else判断即可
你题目的解答代码如下:
#include <stdio.h>
#include <math.h>
float fun(float x)
{
if (x<2)
return x;
else if (x>=2 && x<8)
return tan(3-x)+3;
else if (x>=8)
return 6*log(x)+x*x;
}
int main()
{
float x;
scanf("%f",&x);
printf("%f\n",fun(x));
return 0;
}
如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!
代码如下:
#include <stdio.h>
#include <math.h>
double fun(double x)
{
double y;
if(x<2)
y = x;
else if(x>=2 && x<8)
y = tan(3-x)+3;
else
y = 6*log(x)+x*x;
return y;
}
int main()
{
double x,y;
printf("请输入x的值:");
scanf("%lf",&x);
y = fun(x);
printf("%lf",y);
return 0;
}