小编use*_*696的帖子

C - 具有多个案例编号的开关

所以我的教授要求我们创建一个switch语句.我们只允许使用"SWITCH"语句来执行该程序.他希望我们输入一个数字然后显示它,如果它在数字范围内,将显示如下所示的公文包编号.现在......我知道对于这种类型的程序,使用IF语句更容易.做案例1:案例2:案例3 ......案例30将起作用,但由于数字范围将花费太多时间.

#include <stdio.h>
main()
{
      int x;
      char ch1;
      printf("Enter a number: ");
      scanf("%d",&x);
      switch(x)
      {
                 case 1://for the first case #1-30
                 case 30:
                      printf("The number you entered is >= 1 and <= 30");
                      printf("\nTake Briefcase Number 1");
                      break;         
                 case 31://for the second case #31-59
                 case 59:
                      printf("The number you entered is >= 31 and <= 59");
                      printf("\nTake Briefcase Number 2");
                      break;                 
                 case 60://for the third case #60-89
                 case 89:
                      printf("The number you entered is …
Run Code Online (Sandbox Code Playgroud)

c case switch-statement

14
推荐指数
3
解决办法
8万
查看次数

标签 统计

c ×1

case ×1

switch-statement ×1