C语言填空:数学分段函数 switch case理解

/*有一函数: y= x            (x<10)             输入x的值,求y的值。
             y=3x -2         (10≤x<50)
             y=4x+1         (50≤x<100)
                y=5x            (x≥100)*/6void main()
{    int x,y;
   【1】 t;
   printf("input x=:");
   scanf("【2】",&x);
   if(x<10)  【3】;
      else if(x>=100)  t=10;
              else4】;
   switch(t)
  {     case 0:  y=x; break;
          case 1: 
          case 2:
          case 3: 
          case 4:  y=3*x-2;break;
          case 5: 
          case 6: 
          case 7:
          case 8: 
          case 9:  【5break;
          case 10:  y=5*x;
   }
printf("y=%d",y);
}
/*有一函数: y= x            (x<10)             输入x的值,求y的值。
             y=3x -2         (10≤x<50)
             y=4x+1         (50≤x<100)
                y=5x            (x≥100)*/
#include <stdio.h>            
void main()
{    int x,y;
   int t;
   printf("input x=:");
   scanf("%d",&x);
   if(x<10) t=0;
      else if(x>=100)  t=10;
              else t=x/10;
   switch(t)
  {     case 0:  y=x; break;
          case 1: 
          case 2:
          case 3: 
          case 4:  y=3*x-2;break;
          case 5: 
          case 6: 
          case 7:
          case 8: 
          case 9:  y=4*x+1;break;
          case 10:  y=5*x;
   }
printf("y=%d",y);
}

 

posted @ 2023-02-07 20:28  myrj  阅读(243)  评论(0编辑  收藏  举报