Program to find if a character is vowel or Consonant

Given a character, check if it is vowel or consonant. Vowels are ‘a’, ‘e’, ‘i’, ‘o’ and ‘u’. All other characters (‘b’, ‘c’, ‘d’, ‘f’ ….) are consonants.

Examples:



Input : x = 'c'
Output : Consonant

Input : x = 'y'
Output : Vowel

We check whether given character matches any of the 5 vowels. If yes, we print “Vowel”, else we print “Consonant”.

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

// CPP program to check if a given character
// is vowel or consonant.
#include <iostream>
using namespace std;
  
// Function to check whether a character is
// vowel or not
void vowelOrConsonant(char x)
{
    if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u')
        cout << "Vowel" << endl;
    else
        cout << "Consonant" << endl
}
  
// Driver code
int main()
{
    vowelOrConsonant('c');
    vowelOrConsonant('e');
    return 0;
}

chevron_right


Java

filter_none

edit
close

play_arrow

link
brightness_4
code

// java program to check if a given 
// character is vowel or consonant.
import java.io.*;
  
public class GFG {
  
    // Function to check whether a 
    // character is vowel or not
    static void vowelOrConsonant(char x)
    {
        if (x == 'a' || x == 'e' || x == 'i' ||
                          x == 'o' || x == 'u')
            System.out.println("Vowel");
        else
            System.out.println("Consonant");
    }
  
    // Driver code
    static public void main(String[] args)
    {
        vowelOrConsonant('c');
        vowelOrConsonant('e');
    }
}
  
// This code is contributed by vt_m.

chevron_right


Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python3 program to check if a given 
# character is vowel or consonant.
  
# Function to check whether a character 
# is vowel or not
def vowelOrConsonant(x):
  
    if (x == 'a' or x == 'e' or
        x == 'i' or x == 'o' or x == 'u'):
        print("Vowel")
    else:
        print("Consonant")
  
# Driver code
vowelOrConsonant('c')
vowelOrConsonant('e')
      
# This code is contributed by 
# mohit kumar 29

chevron_right


C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to check if a given
// character is vowel or consonant.
using System;
  
public class GFG {
  
    // Function to check whether a 
    // character is vowel or not
    static void vowelOrConsonant(char x)
    {
        if (x == 'a' || x == 'e' || x == 'i' || 
                          x == 'o' || x == 'u')
            Console.WriteLine("Vowel");
        else
            Console.WriteLine("Consonant");
    }
  
    // Driver code
    static public void Main()
    {
        vowelOrConsonant('c');
        vowelOrConsonant('e');
    }
}
  
// This code is contributed by vt_m.

chevron_right


PHP

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP program to check if a given 
// character is vowel or consonant.
  
// Function to check whether a 
// character is vowel or not
function vowelOrConsonant($x)
{
    if ($x == 'a' || $x == 'e' || 
        $x == 'i' || $x == 'o' || 
        $x == 'u')
        echo "Vowel" . "\n";
    else
        echo "Consonant" . "\n";
}
  
// Driver code
vowelOrConsonant('c');
vowelOrConsonant('e');
  
// This code is contributed 
// by Akanksha Rai
?>

chevron_right



Output:

Consonant
Vowel

How to handle capital letters as well?

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

// CPP program to check if a given character
// is vowel or consonant.
#include <iostream>
using namespace std;
  
// Function to check whether a character is
// vowel or not
void vowelOrConsonant(char x)
{
    if (x == 'a' || x == 'e' || x == 'i' || 
        x == 'o' || x == 'u' || x == 'A' || 
        x == 'E' || x == 'I' || x == 'O' || x == 'U')
        cout << "Vowel" << endl;
    else
        cout << "Consonant" << endl;
}
  
// Driver code
int main()
{
    vowelOrConsonant('c');
    vowelOrConsonant('E');
    return 0;
}

chevron_right


Java

filter_none

edit
close

play_arrow

link
brightness_4
code

// java program to check if a given 
// character is vowel or consonant
import java.io.*;
  
public class GFG {
  
    // Function to check whether a 
    // character is vowel or not
    static void vowelOrConsonant(char x)
    {
        if (x == 'a' || x == 'e' || x == 'i' ||
            x == 'o' || x == 'u' || x == 'A' ||
            x == 'E' || x == 'I' || x == 'O' || x == 'U')
            System.out.println("Vowel");
        else
            System.out.println("Consonant");
    }
  
    // Driver code
    static public void main(String[] args)
    {
        vowelOrConsonant('c');
        vowelOrConsonant('E');
    }
}
  
// This article is contributed by vt_m.

chevron_right


Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python 3 program to check if a given 
# character is vowel or consonant.
  
# Function to check whether a 
# character is vowel or not
def vowelOrConsonant(x):
    if (x == 'a' or x == 'e' or x == 'i' or 
        x == 'o' or x == 'u' or x == 'A' or 
        x == 'E' or x == 'I' or x == 'O' or 
        x == 'U'):
        print("Vowel")
    else:
        print("Consonant")
  
# Driver code
if __name__ == '__main__':
    vowelOrConsonant('c')
    vowelOrConsonant('E')
  
# This code is contributed by
# Sanjit_Prasad

chevron_right


C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to check if a given 
// character is vowel or consonant
using System;
public class GFG {
  
    // Function to check whether a
    // character is vowel or not
    static void vowelOrConsonant(char x)
    {
        if (x == 'a' || x == 'e' || x == 'i' ||
            x == 'o' || x == 'u' || x == 'A' || 
            x == 'E' || x == 'I' || x == 'O' || x == 'U')
            Console.WriteLine("Vowel");
        else
            Console.WriteLine("Consonant");
    }
  
    // Driver code
    static public void Main()
    {
        vowelOrConsonant('c');
        vowelOrConsonant('E');
    }
}
  
// This article is contributed by vt_m.

chevron_right


PHP

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP program to check if a given character
// is vowel or consonant.
  
// Function to check whether a 
// character is vowel or not
function vowelOrConsonant($x)
{
    if ($x == 'a' || $x == 'e' || $x == 'i' || 
        $x == 'o' || $x == 'u' || $x == 'A' || 
        $x == 'E' || $x == 'I' || $x == 'O' || 
        $x == 'U')
        echo "Vowel" . "\n";
    else
        echo "Consonant" . "\n";
}
  
// Driver code
vowelOrConsonant('c');
vowelOrConsonant('E');
  
// This code is contributed
// by Akanksha Rai
?>

chevron_right



Output:

Consonant
Vowel

This article is contributed by Kartik. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.



My Personal Notes arrow_drop_up



Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.