You are here

switch case in C

switch is a keyword of C language.

Example C program explaining use of switch

#include<stdio.h>

main()
{
   int n;
   
   printf("Enter a number from 1, 2 or 3.\n");
   scanf("%d", &n);
   
   switch(n)
   {
      case 1:
     
      case 2:
     
      case 3:
              printf("Thanks!\n");
              break;
     
      default:
              printf("You didn't did what I said.\n");
   }
   
   return 0;
}  

Share this