为什么在这个程序中d=2执行case2,d=4执行case3?怎样使d=2执行case1?

来源:4-16 分支结构之switch语句

qq_幽伤残念_0

2018-03-17 20:42

#include <stdio.h>
void main ()
{
 double td[4][20] =
 {0.3,0.5,0.8,1.2,2,3,4,6,10,14,25,40,60,0.10,0.14,0.25,0.40,0.60,1.0,1.4,
 0.4,0.6,1,1.5,2.5,4,5,8,12,18,30,48,75,0.12,0.18,0.30,0.48,0.75,1.2,1.8,
 0.4,0.6,1,1.5,2.5,4,6,9,15,22,36,58,90,0.15,0.22,0.36,0.58,0.90,1.5,2.2,
 0.5,0.8,1.2,2,3,5,8,11,18,27,43,70,110,0.18,0.27,0.43,0.70,1.10,1.8,2.7,};
 int it, d = 0, n = 0;
 
    printf("输入公称尺寸:");
 scanf("%d",&d);
 printf("输入公差等级:IT");
 scanf("%d",&it);
 
 switch(d)
 {
  case 1:
   d > 0&&d <= 3;n = 0;break;
  case 2:
   d > 3&&d <= 6;n = 1;break;
  case 3:
   d > 6&&d <= 10;n = 2;break;
  case 4:
   d > 10&&d <= 18;n = 3;break;
  
  default:printf ("\n输入错误!请重新输入。");
 }
 if (d > 0&&d <= 18)
 printf("尺寸%d的IT%d公差是:%lf",d,it,td[n][it+1]);
}

写回答 关注

1回答

  • qq_最美的痕迹叫做回憶_0
    2018-03-17 23:41:45

    不知道啊 好难

C语言入门

C语言入门视频教程,带你进入编程世界的必修课-C语言

926028 学习 · 20793 问题

查看课程

相似问题