C Program To Check If The Input Is Vowel or Consonant

C Program To Check If The Input Is Vowel or Consonant: In this program, we will learn to write a code to check if the input is vowel or consonant.

C Program To Check If The Input Is Vowel or Consonant


In this program we use:
  • Switch Statement
  • Default statement
  • Break statement
  • Programming Operators

Working:
  • The five letters A, E, I, O, U both including uppercase and lowercase are called vowels. All other alphabets except vowels are called consonants.
  • This program will always assume the input to be an Alphabet.
  • If we don't use break; statement all the cases following the valid case are executed and evaluated.
  • default; statement is executed if all the above cases are false. It is similar to the else statement of if-else code.
Source Code:
#include<stdio.h>

int main()
{
    printf("\t\t\tScribbled Writer\n\n");
    char ch;
    printf("Enter a Character :  ");
    scanf("%c", &ch);

    switch(ch)
    {
        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.\n", ch);
            break;
         default:
            printf("%c is a consonant.\n", ch);
    }
    printf("\n\tHappy Coding!\n");
    return 0;
}


Output:

Ex-1
       Scribbled Writer
a is a vowel.
       Happy Coding!

Ex-2

     Scribbled Writer
G is a consonant.
        Happy Coding!

2 comments: