Q. Write a program to check whether a character is vowel or consonant.



Vowel :- In English, five alphabets A, E, I, O, and U are called as Vowels.
Consonant :- In English, all alphabets other than vowels are Consonant.
For Example :-
Input = A
Output = A is Vowel.
So as we can see that A is alphabets which is Vowel. So, the output is "A is Vowel".

Algorithm to check whether a character is vowel or consonant

START
Step 1 - Input the alphabets.
Step 2 - Check if the alphabets is (a, e, i, o, u) if alphabet is among these then it is vowel.
Step 3 - If the alphabets is vowel than print Vowel otherwise print Consonant.
STOP


Program to check whether a character is vowel or consonant

  • C
  • C++
  • Java
  • Python
  • C#
  • PHP
  • #include <stdio.h>
    int main() {
    char c='P';
    int lc, uc;
    // evaluates to 1 if variable c is lowercase
    lc = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
    // evaluates to 1 if variable c is uppercase
    uc = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
    // evaluates to 1 if c is either lowercase or uppercase
    if (lc || uc)
    printf("%c is a vowel.", c);
    else
    printf("%c is a consonant.", c);
    return 0;
    }
    
    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
    char c='P';
    int lc, uc;
    // evaluates to 1 (true) if c is a lowercase vowel
    lc = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
    // evaluates to 1 (true) if c is an uppercase vowel
    uc = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
    // evaluates to 1 (true) if either lc or uc is true
    if (lc || uc)
    cout << c << " is a vowel.";
    else
    cout << c << " is a consonant.";
    return 0;
    }
    
    public class LFC
    {
    public static void main(String args[])
    {
    char ch='P';
    if(ch=='a' || ch=='A' || ch=='e' || ch=='E' ||
    ch=='i' || ch=='I' || ch=='o' || ch=='O' ||
    ch=='u' || ch=='U')
    {
    System.out.printf("%c is a Vowel",ch);
    }
    else
    {
    System.out.printf("%c is a Consonant",ch);
    }
    }
    }
    
    # Python Program to check character is Vowel or Consonant
    ch = 'P'
    if(ch == 'a' or ch == 'e' or ch == 'i' or ch == 'o' or ch == 'u' or ch == 'A'
    or ch == 'E' or ch == 'I' or ch == 'O' or ch == 'U'):
    print(ch, "is a Vowel")
    else:
    print(ch, "is a Consonant")
    
    using System;
    public class LFC
    {
    public static void Main(string[] args)
    {
    char ch='P';
    if((ch >= 'A' && ch <= 'Z')||ch >= 'a' && ch <= 'z')
    {
    if (ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i'
    || ch == 'I' || ch == 'o' || ch == 'O' || ch == 'u' || ch == 'U')
    {
    Console.WriteLine(ch + " is a vowel");
    }
    else
    {
    Console.WriteLine(ch + " is a consonant");
    }
    }
    else
    {
    Console.WriteLine(ch + " is not an alphabet");
    }
    }
    }
    
    function check_vowel($ch) 
    { 
    if ($ch == 'a' || $ch == 'e' ||  
    $ch == 'i' || $ch == 'o' ||  
    $ch == 'u') 
    echo "$ch is aVowel" ; 
    else
    echo "$ch is a Consonant"; 
    } 
    // Driver code 
    check_vowel('P'); 
    
    #include <stdio.h>
    int main() {
    char c='P';
    int lc, uc;
    // evaluates to 1 if variable c is lowercase
    lc = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
    // evaluates to 1 if variable c is uppercase
    uc = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
    // evaluates to 1 if c is either lowercase or uppercase
    if (lc || uc)
    printf("%c is a vowel.", c);
    else
    printf("%c is a consonant.", c);
    return 0;
    }
    

    Output

    P is a consonant.
    




    Recommended Programs

       Program to find length of a string.
       Program to print floyds triangle.