解题思路:
用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 人评分
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:815 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:655 |
简单的a+b (C++语言代码)浏览:860 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:867 |
众数问题 (C语言代码)浏览:830 |
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:938 |
【绝对值排序】 (C语言代码)浏览:825 |
三角形 (C语言代码)浏览:915 |
C语言程序设计教程(第三版)课后习题9.10 (C语言代码)浏览:836 |
1013题解浏览:561 |