Associate several case values with one group of statements. - C Statement

C examples for Statement:switch

Description

Associate several case values with one group of statements.

Demo Code

#include <stdio.h> 
#include <ctype.h> 
int main(void) {

   char ch = 'e';

   switch (tolower(ch)) {
   case 'a': case 'e': case 'i': case 'o': case 'u':
      printf("The character is a vowel.\n");
      break;/*from www  .  j  a va 2 s  . co  m*/

   case 'b': case 'c': case 'd': case 'f': case 'g': case 'h': case 'j': case 'k':
   case 'l': case 'm': case 'n': case 'p': case 'q': case 'r': case 's': case 't':
   case 'v': case 'w': case 'x': case 'y': case 'z':
      printf("The character is a consonant.\n");
      break;

   default:
      printf("The character is not a letter.\n");
      break;
   }

   return 0;
}

Result


Related Tutorials