The Program in C# Sharp program to check whether an alphabet is a vowel or consonant is given below:
using System;
namespace VowelOrConsonant
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello Codeauri Family,enter an alphabet here to check if its a vowel or consonant: ");
char ch = char.Parse(Console.ReadLine());
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' ||
ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')
{
Console.WriteLine(ch + " is a vowel.");
}
else
{
Console.WriteLine(ch + " is a consonant.");
}
}
}
}
Output:
Hello Codeauri Family,enter an alphabet here to check if its a vowel or consonant:
c
c is a consonant.
Pro-Tips💡
Here are the step by step execution of above program:
- The code starts with the “using System” directive, which brings in the System namespace and makes its members available in the code.
- The code then defines a namespace “VowelOrConsonant”, which is a way of organizing code into logical groups.
- Within the namespace, there is a class “Program” that contains the code logic.
- In the class, the Main method is the entry point of the program, which gets executed first when the program runs.
- The Main method starts by printing a message on the console asking the user to enter an alphabet.
- The code then reads the input from the console and converts it to a char variable “ch”.
- The code then checks if “ch” is one of the ten vowels (uppercase or lowercase) and prints a message indicating that the alphabet is a vowel.
- If “ch” is not one of the ten vowels, the code prints a message indicating that the alphabet is a consonant.
- The code ends with the closing of the Main method and the class, and the namespace.
Learn C-Sharp ↗
C-sharp covers every topic to learn about C-Sharp thoroughly.
Learn C Programming ↗
C-Programming covers every topic to learn about C-Sharp thoroughly.
Learn C++ Programming↗
C++ covers every topic to learn about C-Sharp thoroughly.