C语言计算分段函数

2022-08-12 教育 81阅读
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 && y>0)
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
#include

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(y>0)
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

int main(void)
{
int score = 0;
printf("Please input a score between 0-100:\n");
scanf("%d", &score);
if(score<0 || score>100)
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;
}
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com