求用c++当x<1时y=x,当1<=x<10时y=2x-1,当x>=10时y=3x-1的程序

2025-03-06 18:10:10
推荐回答(2个)
回答1:

float x,y;
if(x<1) y=x;
else if(x>=10) y=3*x-1;
else y=2*x-1;

回答2:

#include
using namespace std;
float function(float);
void main()
{
float x;
cout<<"Please input the value of parameter x:";
cin>>x;
cout<<"/ny="<}
float function(float x)
{
if(x<1)
{
y=x;
}
else if(x>=10)
{
y=3*x-1;
}
else
{
y=2*x-1;
}
return y;
}