c语言编一个程序,根据输入的x值计算yz并输出,如图?

自己编的调试错误了,希望有完整的过程

第1个回答  2020-03-30

#include <stdio.h>

#include <math.h>

void main()

{

float x,y,z;

printf("Please input x : ");

scanf("%f",&x);

if(x<=2.5)

y=x*x+1;

else

y=x*x-1;

if(x>=1&&x<2)

z=3*x+5;

else if(x>=2&&x<3)

z=2*sin(x)-1;

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

z=sqrt(1+x*x);

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

z=x*x-2*x+5;

printf("y=%f\nz=%f\n",y,z);

}


第2个回答  2020-03-30
#include <stdio.h>
#include <string.h>
#include <math.h>

double z(double x) {
if (1 <= x < 2) {
return x * x * x + 5;
} else if (2 <= x < 3) {
return 2 * sin(x) - 1;
} else if (3 <= x < 5) {
return sqrt(1 + x * x);
} else if (5 <= x < 8) {
return x * x - 2 * x + 5;
}
return x;
}

double y(double x) {
if (x <= 2.5) {
return x * x + 1;
}
return x * x - 1;
}

int main() {
double x = 0;
printf("input a x : ");
scanf("%lf", &x);
printf("y = %f\t", y(x));
printf("z = %f\n", z(x));

}追问

我想检测多个分支,但是用int i;for(i=1;i<=n;i++)的形式不行,有什么办法吗

追答

不,你不想

追问

啊改了一下成功运行了

本回答被提问者采纳
相似回答