由题意得:当x>2且x≤10时 y=x(x+2);当x>-1,x≤2时 y=2x;当x ≤ -1时y=x-1;直接用if语句。(这道题不是很难,分析就到这里了吧)
#include <iostream>
using namespace std;
int main()
{
int x,y;
cin >> x;
if(x > 2 && x <= 10)
y = x*(x + 2);
else if(x > -1 && x <= 2)
y = 2*x;
else if(x <= -1){
y = x - 1;}
cout << y;
return 0;
}