Program to identify if the character is a vowel or consonant

Program to identify if the character is a vowel or consonant

10 May 2023

10 May 2023

Write a program to identify if the character is a vowel or consonant?


Description about the Program to identify if the character is a vowel or consonant

Take an input character from the user and check whether the given input is vowel or consonant.

Input

A

Output

Vowel 

Input 

m

Output

Consonant

Input 

3

Output

Invalid input


C Program to identify if the character is a vowel or consonant

#include <stdio.h>

int main()

{

    char c;

    printf("Enter a character");

    scanf("%c", &c);

    if(c=='A' || c=='E' || c=='I' || c=='O' || c=='U' || c=='a' || c=='e' || c=='i' || c=='o' ||c=='u')

    printf("Vowel");

    else if(!((c>='a' && c<='z') || (c>='A' && c<='Z')))

    printf("Invalid input");

    else

    printf("consonant");

    return 0;

}


C++ Program to identify if the character is a vowel or consonant

#include <iostream>

using namespace std;

int main()

{

char c;

cout<<"Enter a character: ";

cin>>c;

if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||c=='A'||c=='E'||c=='I'||c=='O'||c=='U')

    cout<<"vowel";

else if(!((c>='a' && c<='z') || (c>='A' && c<='Z')))

cout<<"invalid input";

else

    cout<<"consonant";

return 0;

}


Java Program to identify if the character is a vowel or consonant

 

import java.util.Scanner;

public class Main

{

public static void main(String[] args)

    {

    Scanner sc=new Scanner(System.in);

    System.out.println("Enter a character");

    char c = sc.next().charAt(0);

    if(c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U'|| c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') 

        System.out.println(" Vowel");

    else if((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))

        System.out.println("Consonant");

    else

        System.out.println("Invalid input");

    }       

}


Python Program to identify if the character is a vowel or consonant

print("Enter a character")

c = input() 

if (c== 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u' or c== 'A' or c == 'E' or c == 'I' or c == 'O' or c == 'U'): 

    print("Vowel") 

elif ((c >= 'A' and c <= 'Z') or (c >= 'a' and c <= 'z')):

    print("Consonant")

else:

    print("Invalid input")

 



Related Articles

Ask Us Anything !