C# program to take a character and tells its vowel or consonant
Following program shows you how to take a character and tells its vowel or consonant.
In this program we get a character from user and shows it's vowel or consonant using if condition
using System;
class MainClass {
public static void Main (string[] args) {
Console.WriteLine ("Enter a character:");
char input = Char.Parse (Console.ReadLine());
if (input == 'a' || input == 'A' || input == 'e' || input == 'E' || input == 'i' || input == 'I' || input == 'o'
|| input == 'O' || input == 'u' || input == 'U') {
Console.WriteLine("Its a vowel");
} else if ((input >= 'a' && input <= 'z') || (input >= 'A' && input <= 'Z')) {
Console.WriteLine("Its a consonant");
} else {
Console.WriteLine("Invalid input please enter an alphabet");
}
}
}
Output:
Example1:
Enter a character:
u
Its a vowel
Example2:
Enter a character:
f
Its a consonant
Example3:
Enter a character:
8
Invalid input please enter an alphabet