0
已采纳
double x,y;
cin>>x;
if (x<=-2)
y=x*3+4.5;
if (x<=2 and x>-2 )
y=x*x+1;
if (x<=15 and x>2)
y=x/3+x/5;
if (x>15)
y=x/2+6.5;
printf("%.3f",y);
注意头文件有两个
#include <iostream>
#include <cstdio>
0
0
0
核心代码如下
if (x<=-2)
y=x*3+4.5;
if (x<=2 and x>-2 )
y=x*x+1;
if (x<=15 and x>2)
y=x/3+x/5;
if (x>15)
y=x/2+6.5;
printf("%.3f",y);
0
if (x<=-2)
{
y=x*3+4.5;
}
if (x>-2&&x<=2)
{
y=x*x+1;
}
if (x>2&&x<=15)
{
y=x/3+x/5;
}
if (x>15)
{
y=x/2+6.5;
}
0
if (x<=-2)
{
y=x*3+4.5;
}
if (x>-2&&x<=2)
{
y=x*x+1;
}
if (x>2&&x<=15)
{
y=x/3+x/5;
}
if (x>15)
{
y=x/2+6.5;
}
0