switch statement in C programming language

The switch statement in C is used for handling multiple operations for the different possibles values of a single variable called switch variable. Each value is called a case, and the variable being switched on is checked for each switch case.

The syntax of switch statement in c language is :
switch(variable)
{
      case 1:
            code to be executed;
            break;
      case 2:
            code to be executed;
            break;
      .......
      .......
      default:
            code to be executed;
            break;
}

Example :
#include <stdio.h>
int main()
{
      int day;
      printf("Enter a number between 1 to 7 : ");
      scanf("%d",&day);
      switch(day)
      {
            case 1:
                  printf("Monday");
                  break;
            case 2:
                  printf("Tuesday");
                  break;
            case 3:
                  printf("Wednesday");
                  break;
            case 4:
                  printf("Thursday");
                  break;
            case 5:
                  printf("Friday");
                  break;
            case 6:
                  printf("Saturday");
                  break;
            case 7:
                  printf("Sunday");
                  break;
            default:
                  printf("Enter a vaild number");
      }
      return 0;
}

Output :
Enter a number between 1 to 7 : 2
Tuesday

0 Comments