All articles
c

A program to explain SWITCH CASE, which has CASE blocks without statements

Share this article

Share on LinkedIn Share on X (formerly Twitter)

C Programming Language 024

The following code shows how to write a program to explain SWITCH CASE, which has CASE blocks without statements. Read a character and print whether it is a vowel or a consonant.

Program

#include <stdio.h>
 
void main()
{
    char c;
 
    printf("Enter an alphabet: ");
    scanf("%c", &c);
 
    switch (c)
    {
    case 'a':
    case 'A':
    case 'e':
    case 'E':
    case 'i':
    case 'I':
    case 'o':
    case 'O':
    case 'u':
    case 'U':
        printf("%c is a vowel", c);
        break;
    default:
        printf("%c is a consonant", c);
    }
 
    printf("\n");
}

Result

Enter an alphabet: w
w is a consonant
Enter an alphabet: A
A is a vowel

Comments