You are here

switch case in C

switch is a keyword of C language.

Example C program explaining use of switch

  1. #include<stdio.h>
  2.  
  3. main()
  4. {
  5.    int n;
  6.    
  7.    printf("Enter a number from 1, 2 or 3.\n");
  8.    scanf("%d", &n);
  9.    
  10.    switch(n)
  11.    {
  12.       case 1:
  13.      
  14.       case 2:
  15.      
  16.       case 3:
  17.               printf("Thanks!\n");
  18.               break;
  19.      
  20.       default:
  21.               printf("You didn't did what I said.\n");
  22.    }
  23.    
  24.    return 0;
  25. }