#includestdio.h
网站建设哪家好,找创新互联!专注于网页设计、网站建设、微信开发、成都微信小程序、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了惠水免费建站欢迎大家使用!
void main()
{
float x,y;
scanf("%f",x);
if(x0)
y=x*x;
else if(x==0)
y=2*x-1;
else
y=-3*x*x-1 ;//这里少个分号
printf("%.2f",y);
}
#include
int main()
{
int x,y;
scanf("%d",x);
if(0xx10) y=3*x+2;
else
{if(x=0) y=0;
else
{if (x0) y=x*x;
else printf("go die\n");
}
}
printf("%d",y);
return 0;
}该程序的分段函数如下:
f(x)=3x+2 (0x10)
f(x)=1 (x=0)
f(x) = x*x (x0)
#include stdio.h
#include math.h
void main()
{
float x;
double y;
printf("Please input the value of x:");
scanf("%f",x);
if(x=-10x=4)
{
y=fabs(x-2);
printf("y=%.2f\n",y);
}
else if(x=5x=7)
{
y=x+10;
printf("y=%.2f\n",y);
}
else if(x=8x=12)
{
y=pow(x,4);
printf("y=%.2f\n",y);
}
else
printf("No answer\n");
}
输入数用scanf()函数;
分段用switch()函数;
1、绝对值用math库里面的abs()函数
2、e^x用math库里面的pow(e,x)函数
3、同理指数的都有pow()函数,
4、cos函数也是math库里面的double
cos(double
x)函数
自己动手吧,我已经把难点全部说出来了!
希望可以帮到你,如果满意请采纳!
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;
}
帮你改了下代码,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;//缺少分号
}