Basic Programming C# Examples

C# Program to check If an alphabet is Vowel/Consonant

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:

  1. The code starts with the “using System” directive, which brings in the System namespace and makes its members available in the code.
  2. The code then defines a namespace “VowelOrConsonant”, which is a way of organizing code into logical groups.
  3. Within the namespace, there is a class “Program” that contains the code logic.
  4. In the class, the Main method is the entry point of the program, which gets executed first when the program runs.
  5. The Main method starts by printing a message on the console asking the user to enter an alphabet.
  6. The code then reads the input from the console and converts it to a char variable “ch”.
  7. 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.
  8. If “ch” is not one of the ten vowels, the code prints a message indicating that the alphabet is a consonant.
  9. 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.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

Related Posts

Programming Languages( Types, Pros and Cons)-Codeauri

What are the types or levels of Programming Languages? The types or levels of programming languages are divided into two types: Types Of Programming Languages: 1.Machine-level Language :1st…

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

Leave a Reply

Your email address will not be published. Required fields are marked *

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X