编辑代码


#include <stdio.h>
int main ()
{
    float x=-1,y;
    int n;
    printf("输入x的值:");
    scanf("%f\n",&x);
    n=x/10;
    switch(n)
    {
        case 1:
        case 2:
            y=3*x-1;
            break;
        case 3:
        case 4:
        case 5:
            y=4*x-2;
            break;
        default:
            y=(x<1)?x:x<10?2*x-1:5*x;
            break;        
    }
    printf("y的值是:%f\n",y);
    
   
	return 0;
}