问答详情
源自:6-11 多维数组的遍历

case条件选择语句

case条件选择语句  具体例题

提问者:qq_落花微夢如雨_03608775 2018-03-20 17:48

个回答

  • Akane_miku
    2018-03-22 12:51:57

    switch-case的简单计算器

    #include <stdio.h>

    int main( )

    {

    double a, b;

      char op;

      scanf("%lf%c%lf", &a, &op, &b);

      switch (op)

      {

          case  '+':

        printf("%lf + %lf = %lf\n", a, b, a + b);

      break;

      case  '-':

        printf("%lf - %lf = %lf\n", a, b, a - b);

      break; 

      case  '*':

    printf("%lf * %lf = %lf\n", a, b, a * b);

      break;

      case  '/':

      if (b != 0)

      printf("%lf / %lf = %lf\n", a, b, a / b);

      else

        printf("除数不能是0! \n");

      break;

      }

    }