Program to check whether an alphabet is a vowel or a consonant.

Here, we have a basic program example to check if the alphabet is vowel or consonant using different languages. This program is created in c language, c++, Java, and Python.

Program to check if the alphabet is vowel or consonant in C language

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

    lower_vowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');

    upper_vowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');

    if (lower_vowel || upper_vowel)
        printf("%c is a vowel.", c);
    else
        printf("%c is a consonant.", c);
    return 0;
}

Program to check if the alphabet is vowel or consonant in C++ language

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

    lower_vowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');

    upper_vowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');

    if (lower_vowel || upper_vowel)
        cout<<c<<" is a vowel.";
    else
        cout<<c<<" is a consonant.";
    return 0;
}

Program to check if the alphabet is vowel or consonant in Python language

l = input("Input a letter of the alphabet: ")

if l in ('a', 'e', 'i', 'o', 'u'):
    print("%s is a vowel." % l)
elif l in ('A', 'E', 'I', 'O', 'U'):
    print("%s is a vowel." % l)
else:
    print("%s is a consonant." % l)

Program to check if the alphabet is vowel or consonant in Java language

import java.util.*;
public class VowelConsonant {

    public static void main(String[] args) {

        char ch;

	   Scanner s=new Scanner(System.in);
	   System.out.println("Input a character: ");
	   ch = s.next().charAt(0);

        if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' )
            System.out.println(ch + " is vowel");
        else if(ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U' )
             System.out.println(ch + " is vowel");
        else
            System.out.println(ch + " is consonant");

    }
}