Alphabet

C program to check Vowel or consonant using switch case

C program to check Vowel or consonant using switch case

In this article, we will discuss the concept of the C program to Check Vowel or consonant using switch case statements

In this post, we are going to learn how to check the vowels and consonants using switch statements in C  programming language

 

Check vowel and consonants

C program to check Vowel or consonant using switch case with the break

The program allows to enter an Alphabet and it checks and displays whether the given alphabet is vowel or consonant with the break statements

Program 1

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char ch;
    printf("Enter any Alphabet\n"); //input alphabet from user
    scanf("%c",&ch);//store the Entered Alphabet in ch

    switch(ch){
    //check lower case vowel letters
    case 'a':
    printf("%c is a vowel",ch);
    break;

    case 'e':
    printf("%c is a vowel",ch);
    break;

    case 'i':
    printf("%c is a vowel",ch);
    break;

    case 'o':
    printf("%c is a vowel",ch);
    break;

    case 'u':
    printf("%c is a vowel",ch);
    break;

    //check upper case vowel letters
    case 'A':
    printf("%c is a vowel",ch);
    break;

    case 'E':
    printf("%c is a vowel",ch);
    break;

    case 'I':
    printf("%c is a vowel",ch);
    break;

    case 'O':
    printf("%c is a vowel",ch);
    break;

    case 'U':
    printf("%c is a vowel",ch);
    break;

    default:
    printf("%c is a consonant",ch);
    break;
    }
    getch();

    return 0;
    }

When the above code is executed, it produces the following result

case 1

Enter any Alphabet
a
a is a vowel

 

case 2

Enter any Alphabet
E
E is a vowel

 

case 3

Enter any Alphabet
M
M is a consonant


case 4

Enter any Alphabet
y
y is a consonant

Approach

  • Define a character variable ch
  • The program is asked the user to enter an Alphabets to check whether vowel or consonant
  • Entered character is stored in the ch variable
  • Define cases for the character ch with vowel character both capital and small
  • Next, the program checks every case using the given character.
  • Finally, it displays whether the given character is vowel or consonant

 

C program to check Vowel or consonant using switch case without the break

The program allows to enter an Alphabet and it checks and displays whether the given alphabet vowel or consonant without the break statements

Program 2

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char ch;
    printf("Enter any Alpabet\n"); //input alphabet from user
    scanf("%c",&ch);//store the Entered Alphabet in ch

    switch(ch){
    //check lower case vowel letters
    case 'a':
    case 'e':
    case 'i':
    case 'o':
    case 'u':

    //check upper case vowel letters
    case 'A':
    case 'E':
    case 'I':
    case 'O':
    case 'U':

        printf("%c is a vowel",ch);
        break;

    default:
        printf("%c is a consonant",ch);
        break;

}
    getch();

    return 0;
    }

 

When the above code is executed, it produces the following result

case 1

Enter any Alphabet
e
e is a vowel

 

case 2

Enter any Alphabet
U
U is a vowel

 

case 3

Enter any Alphabet
G
G is a consonant


case 4

Enter any Alphabet
r
r is a consonant

 

Approach

  • Define a character variable ch to check the entered character
  • The program is asked the user to enter an Alphabets to check whether vowel or consonant
  • Entered character is stored in the ch variable
  • Define cases for the character ch with vowel character both capital and small
  • Next, the program checks every case using the given character.
  • Finally, it displays whether the given character is vowel or consonant

 

 

Suggested for you

Data type in C language

Variable in C language

The operator in C language

Switch case statements in C language

 

Similar post

Java program to check Vowel or consonant using switch case statements

C++ program to Check Vowel or consonant using switch case statements

C++ program to Check Vowel or consonant using switch case
C++ Program for count upper or lowercase letter of the given string
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

2 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago