List of Switch case programs with an examples

Switch case statements are an alternate method for long if statements that compare a variable to several ‘integral’ values. The value of the variable given into switch is compared to the value following each of the cases, and when one value matches the value of the variable, the computer continues executing the program at that point.

The basic format for using switch case is outlined below.

switch (n)
{
    case this-value:
        // code to be executed if n is equal to  this-value
        break;

    case this-value2:
        // code to be executed if n is equal to this-value2
        break;
        .
        .
        .
    default:
        // code to be executed if n doesn't match any of the cases
}
  1. Write C++ program to print number of days in a month using switch case
  2. Write C++ program to print day of week name using switch case
  3. Write C++ program to create calculator using switch Statement
  4. Write C++ program to check even or odd number using switch case
  5. Write C++ program to check vowel or consonant using switch case
  6. Write C++ program to print gender (Male/Female) program according to given M/F.
  7. Write C++ Program to find maximum number using switch case.

Leave a Comment