Program to Check if Given Character is Vowel or Consonant
- Write a program to Check if Given Character is Vowel or Consonant in C
- Write a program to Check if Given Character is Vowel or Consonant in C++
- Write a program to Check if Given Character is Vowel or Consonant in Python
- Write a program to Check if Given Character is Vowel or Consonant in PHP
- Write a program to Check if Given Character is Vowel or Consonant in Java
- Write a program to Check if Given Character is Vowel or Consonant in Java Script
- Write a program to Check if Given Character is Vowel or Consonant in C#
Explanation:
Use this reasoning to ascertain whether a given character is a vowel or a consonant:
Steps to Check
- Input Validation: Ensure the input is an alphabet character.
- Identify Vowels:
- Vowels in English are: a, e, i, o , u (both uppercase and lowercase: A, E, I, O, U).
- Check if the character belongs to this set.
- Determine Consonants:
- If the character is an alphabet but not a vowel, it is a consonant.
- Handle Non-Alphabet Characters:
- If the input is not an alphabet character, display an appropriate message.
Program to Check if Given Character is Vowel or Consonant
-
C
-
C++
-
Python
-
PHP
-
JAVA
-
Java Script
-
C#
#include <stdio.h> int main() { char ch; // Input a character printf("Enter a character: "); scanf("%c", &ch); // Check if the character is a vowel or consonant if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') { printf("The character is a vowel.\n"); } else { printf("The character is a consonant.\n"); } return 0; }
#include <iostream> using namespace std; int main() { char ch; // Input a character cout << "Enter a character: "; cin >> ch; // Check if the character is a vowel or consonant if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') { cout << "The character is a vowel." << endl; } else { cout << "The character is a consonant." << endl; } return 0; }
ch = input("Enter a character: ") # Check if the character is a vowel or consonant if ch.lower() in ['a', 'e', 'i', 'o', 'u']: print("The character is a vowel.") else: print("The character is a consonant.")
<?php // Input a character $ch = readline("Enter a character: "); // Check if the character is a vowel or consonant if (in_array(strtolower($ch), ['a', 'e', 'i', 'o', 'u'])) { echo "The character is a vowel.\n"; } else { echo "The character is a consonant.\n"; } ?>
import java.util.Scanner; public class VowelOrConsonant { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Input a character System.out.print("Enter a character: "); char ch = scanner.next().charAt(0); // Check if the character is a vowel or consonant if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') { System.out.println("The character is a vowel."); } else { System.out.println("The character is a consonant."); } scanner.close(); } }
let ch = prompt("Enter a character: "); // Check if the character is a vowel or consonant if (['a', 'e', 'i', 'o', 'u'].includes(ch.toLowerCase())) { console.log("The character is a vowel."); } else { console.log("The character is a consonant."); }
using System; class Program { static void Main() { // Input a character Console.Write("Enter a character: "); char ch = Convert.ToChar(Console.ReadLine()); // Check if the character is a vowel or consonant if ("aeiouAEIOU".IndexOf(ch) >= 0) { Console.WriteLine("The character is a vowel."); } else { Console.WriteLine("The character is a consonant."); } } }