
正文
c语言计算分段平方函数 c语音计算分段函数
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
C语言写计算分段函数
#include stdio.h
#include math.h
int main(void)
{
int repeat, ri;
double x, y;
scanf("%d", repeat);
for(ri = 1; ri = repeat; ri++){
scanf("%lf",x);
y=x=0?sqrt(x):pow(x+1,2)+2*x+1/x;
printf("f(%.2f) = %.2f\n", x, y);
}
}
相关问答
Q1: C语言编程 求分段函数的值
#includestdio.h
#includemath.h
void main()
{
int x;
float Y;
printf("please input x\n");
scanf("%d",x);
if(x 0)
Y = 1 + exp(x); //数学函数,计算e的x次方
else if(x == 0)
Y = 1;
else
Y = log(x * x); //数学函数,计算x的平方,以e为底
printf("%.4f\n",Y);
}
please input x
1.0000
Press any key to continue
please input x
1
3.7183
Press any key to continue
please input x
-2
1.3863
Press any key to continue
Q2: c语言求分段函数
帮你改了下代码,VC6测试通过,自己看看吧。
#includestdio.h
int main()
{
float x,y;//根据给定的测试用例,x,y应该为float型
scanf("%f",x);//x为float型,所以改为%f
if(x20)
{
y=x+100;
}
else if(x=20x=100)
{
y=x;
}
else
y=x-100;
printf("x=%f,y=%f\n",x,y);
return 0;//缺少分号
}
Q3: C语言计算分段函数
1. 代码如下,3)需要实际运行时输入测试
int main(void)
{
double x, y, f;
printf("Please input 2 double number in the form of x y:\n");
scanf("%lf%lf", x, y);
if(x=0 y0)
f = 2*x*x + 3*x +1/(x+y);
else if(x=0 y=0)
f = 2*x*x + 3*x +1/(1+y*y);
else
f = 3*sin(x+y)/(2*x*x) + 3*x + 1;
printf("x=%lf, y=%lf, f(x, y)=%lf\n", x, y, f);
return 0;
}
2.代码如下
#include stdio.h
#includemath.h
int main(void)
{
double x, y, f;
printf("Please input 2 double number in the form of x y:\n");
scanf("%lf%lf", x, y);
if(x=0)
{
if(y0)
f = 2*x*x + 3*x +1/(x+y);
else
f = 2*x*x + 3*x +1/(1+y*y);
}
else
f = 3*sin(x+y)/(2*x*x) + 3*x + 1;
printf("x=%lf, y=%lf, f(x, y)=%lf\n", x, y, f);
return 0;
}
3.代码如下
#include stdio.h
int main(void)
{
int score = 0;
printf("Please input a score between 0-100:\n");
scanf("%d", score);
if(score0 || score100)
printf("Wrong input of score!\n");
else if(score=90 score=100)
printf("A\n");
else if(score=80 score=89)
printf("B\n");
else if(score=70 score=79)
printf("C\n");
else if(score=60 score=69)
printf("D\n");
else
printf("E\n");
return 0;
}
c语言计算分段平方函数的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于c语音计算分段函数、c语言计算分段平方函数的信息别忘了在本站进行查找喔。








