Check whether an alphabet is vowel or consonant

Problem statement:- Program to check whether an alphabet is vowel or consonant using switch case.

Data requirement:-

   Input Data:-alphabet

  Output Data:-String output

Program in C

Here is the source code of the C Program to check whether an alphabet is vowel or consonant using switch case.

Code:

#include<stdio.h>
int main()
{
    char alphabet;
    printf("Enter an alphabet:");
    scanf("%c",&alphabet);

    switch(alphabet)
    {
    case 'a':
    case 'A':
    case 'e':
    case 'E':
    case 'i':
    case 'I':
    case 'o':
    case 'O':
    case 'u':
    case 'U':
        printf("It is vowel");
        break;
    default:
        printf("It is consonant");
    }
}

Input/Output:
Enter an alphabet: A
It is vowel

Program in C++

Here is the source code of the C++ Program to check whether an alphabet is vowel or consonant using switch case.

Code:

#include<iostream>
using namespace std;
int main()
{
    char alphabet;
    cout<<"Enter an alphabet:";
    cin>>alphabet;

    switch(alphabet)
    {
    case 'a':
    case 'A':
    case 'e':
    case 'E':
    case 'i':
    case 'I':
    case 'o':
    case 'O':
    case 'u':
    case 'U':
        cout<<"It is vowel";
        break;
    default:
        cout<<"It is consonant";
    }
}

Input/Output:
Enter an alphabet: T
It is consonant

Program in Java

Here is the source code of the Java Program to check whether an alphabet is vowel or consonant using switch case.

Code:

import java.util.Scanner;
public class VowelOrConsonant {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
char alphabet;
    System.out.println("Enter an alphabet:");
    alphabet=cs.next().charAt(0);

    switch(alphabet)
    {
    case 'a':
    case 'A':
    case 'e':
    case 'E':
    case 'i':
    case 'I':
    case 'o':
    case 'O':
    case 'u':
    case 'U':
        System.out.println("It is vowel");
        break;
    default:
       System.out.println("It is consonant");
cs.close();
}
}}

Input/Output:
Enter an alphabet:
i
It is vowel


Program in Python

Here is the source code of the Python Program to check whether an alphabet is vowel or consonant.

Code:

alphabet=input("Enter an alphabet:")
if(alphabet=='a' or alphabet=='A' or alphabet=='e' or alphabet=='E' or alphabet=='i' or alphabet=='I' or alphabet=='o' or alphabet=='O' or alphabet=='u' or alphabet=='U'):
 print("It is Vowel")
else:
 print("It is Consonant")

Input/Output:
Enter an alphabet:K
It is Consonant


Post a Comment

0 Comments