有一分段函数用cin语句输入x的值,求y值。
【程序代码】
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{ int x,y;
cout <<"请输入x的值,求出y的值:"<<endl;
cin >>x;
if (x<1) { y==x; }
else if (x>=1&&x<10){ y=2*x-1; }
else if(x>=10) { y=3*x-1; }
cout <<"当x为"<<x<<"时,"<<"y="<<y;
return 0;
}
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
int x,y;
cout <<"请输入x的值,求出y的值:"<<endl;
cin >>x;
if (x<1)
{
y==x;
}
else if (x>=1&&x<10)
{
y=2*x-1;
}
else if(x>=10)
{
y=3*x-1;
}
cout <<"当x为"<<x<<"时,"<<"y="<<y;
return 0;
}