问题及代码:
#include <iostream>
#include<cmath>
using namespace std;
int main()
{
int t,x;
double y;
cin>>x;
t=(x<2)+(x<6)+(x<10);
switch(t)
{
case 3: //(x<2)、(x<6)、(x<10)全为真时
y=x;break;
case 2: //(x<6)、(x<10)为真时
y=x*x+1;break;
case 1: //(x<10)为真时
y=sqrt(x+1);break;
case 0: //(x>=10)
y=1/(x+1);
}
cout<<y<<endl;
return 0;
}
运行结果: