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


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



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


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



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

Improved By : vt_m



Article Tags :

Be the First to upvote.


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