switch2.c

来自「里面包含很多c语言的源码」· C语言 代码 · 共 49 行

C
49
字号
/* Demonstrates the switch statement correctly. */

#include <stdio.h>

int main( void )
{
   int reply;

   puts("\nEnter a number between 1 and 5:");
   scanf("%d", &reply);

   switch (reply)
   {
     case 0:
         break;
     case 1:
        {
          puts("You entered 1.\n");
          break;
        }
     case 2:
        {
          puts("You entered 2.\n");
          break;
        }
     case 3:
        {
          puts("You entered 3.\n");
          break;
        }
     case 4:
        {
          puts("You entered 4.\n");
          break;
        }
     case 5:
        {
          puts("You entered 5.\n");
          break;
        }
     default:
        {
          puts("Out of range, try again.\n");
        }
   }              /* End of switch */
   return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?