#include <stdio.h>
#include <math.h>
int main()
{
int x,y=0;
scanf("%d",&x);
switch(x)
{
case -2000 ... 1:
y=x;
break;
case 2 ... 5:
y=x*x+1;
break;
case 6 ... 9:
y=sqrt(x+1);
break;
default:
y=1/(x+1);
}
printf("x=%d y=%d\n",x,y);
}
#include <stdio.h>
#include <math.h>
int main()
{
int x, t;
double y = 0;
scanf("%d", &x);
t = x - 2 < 0;
switch (t)
{
case 1:
y = x;
break;
case 0:
switch (x) {
case 2:case 3:case 4:case 5:y = x * x + 1; break;
case 6:case 7:case 8: case 9:y = sqrt(x + 1); break;
default:y = 1 / (x + 1); break;
}
break;
}
printf("%lf", y);
return 0;
}
觉得有用的话采纳一下哈