Write a program to check if a given character is a vowel or consonant.
Input must be any English alphabet
Example:
Input: ch = 'a' Output: Character is vowel
Approach
C
#include <stdio.h>int main(){char ch;printf("Enter a character: ");scanf("%c", &ch);if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u'){printf("Character is vowel");}else if (ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U'){printf("Character is vowel");}else{printf("Character is consonant ");}}
Java
import java.util.Scanner;public class CheckVowelORConsonant {public static void main(String[] args) {System.out.println("Enter a character: ");Scanner sc = new Scanner(System.in);char ch = sc.nextLine().charAt(0);if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {System.out.println("Character is vowel");} else if (ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') {System.out.println("Character is vowel");} else {System.out.println("Character is consonant ");}sc.close();}}
No comments:
Post a Comment