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

22 November 2022

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


Description

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

#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

#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

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

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 !