Program to Check Whether a Character is a Vowel or Not

Description

To check entered character is a vowel or not, check that character is
any one of lowercase a, e, i, o, u and uppercase A, E, I, O, U.

C/C++

/* C Program to Check Whether a Character is a Vowel or Not */
//Save it as CheckVowel.c

#include<stdio.h>
int main(){
    char data;
    printf("Enter a character : ");
    scanf("%c",&amp;data);
	
    //Checking for both upper and lower case
    if(data=='a' || data=='e' || data=='i' || data=='o' || data=='u' || data=='A' ||
       data=='E' || data=='I' || data=='O' || data=='U'){
        printf("%c is a vowel",data);
    }
    else{
        printf("%c is not a vowel",data);
    }
    return 0;
}

Output

Input:
Enter a character : k
Output:
k is not a vowel

Java

/* Java Program to Check Whether a Character is a Vowel or Not */
//Save it as CheckVowel.java

import java.io.*;
import java.util.Scanner;

public class CheckVowel {

	public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
		
        System.out.println("Enter a character : ");
        char data = scanner.next().trim().charAt(0);
				
        //Checking for both upper and lower case
	    if(data=='a' || data=='e' || data=='i' || data=='o' || data=='u' || data=='A' ||
	       data=='E' || data=='I' || data=='O' || data=='U'){
	    	
	        System.out.print(data + " is a vowel");
	    }
	    else{
	    	System.out.print(data + " is not a vowel");
	    }
	}
}

Output

Input:
Enter a character : 
a
Output:
a is a vowel

Related Programs

1) Program to find largest and smallest character in a String
2) Program to swap two strings
3) Program to check String is Palindrome
4) Program to Find ASCII value of a character
5) Program To Print Unique Word Of A String Using Set
6) Print All Unique Words Of A String
7) Find Occurrence Of Each Word In a Sentence
8) Count Number of Words in a String
9) Program to Sort set of strings in alphabetical order
10) check strings are equal or not after concatenation of array of strings with other array of strings
Share Me

Leave a Reply