解题思路:
用if,else
注意事项:
else后面不加条件
参考代码:
#include<iostream>
using namespace std;
int main()
{
int x;
cin >> x;
if(x<1)
{
cout << x;
}
else if(1<=x && x<10)
{
cout << 2*x-1;
}
else
{
cout << 3*x-11;
}
return 0;
}
解题思路:
用if,else
注意事项:
else后面不加条件,第一个代码设了y,第二个没设
参考代码2:
#include<iostream>
using namespace std;
int main()
{
int x,y;
cin >> x;
if(x<1)
{
y=x;
cout << y;
}
else if(x>=1 && x<10)
{
y=2*x-1;
cout << x;
}
else
{
y=3*x-11;
cout << y;
}
return 0;
}
0.0分
2 人评分