w3resource
C# Sharp Programming Exercises

C# Sharp Exercises: Check whether an alphabet is a vowel or consonant


C# Sharp Conditional Statement: Exercise-16 with Solution

Write a C# Sharp program to check whether an alphabet is a vowel or consonant.

Sample Solution:-

C# Sharp Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
public   class exercise16
   {
       static void Main(string[] args)
       {
           char ch;
           Console.Write("\n\n");
           Console.Write("check whether the input alphabet is a vowel or not:\n");
           Console.Write("-----------------------------------------------------");
           Console.Write("\n\n");

           Console.Write("Input an Alphabet (A-Z or a-z) : ");
           ch = Convert.ToChar(Console.ReadLine().ToLower());
           int i=ch;
           if(i>=48 && i<=57)
           {
            Console.Write("You entered a number, Please enter an alpahbet."); 
            }
           else
           {		   
           switch (ch)
           {
                case 'a':
                   Console.WriteLine("The Alphabet is vowel");
                   break;
               case 'i':
                   Console.WriteLine("The Alphabet is vowel");
                    break;
               case 'o':
                   Console.WriteLine("The Alphabet is vowel");
                   break;
               case 'u':
                   Console.WriteLine("The Alphabet is vowel");
                   break;
               case 'e':
                   Console.WriteLine("The Alphabet is vowel");
                   break;
               default:
                   Console.WriteLine("The Alphabet is not a vowel");
                   break;
            }
			}
           Console.ReadKey();
       }
   }
 

Sample Output:

check whether the input alphabet is a vowel or not:                                                           
-----------------------------------------------------                                                             
Input an Alphabet : A                                                                                         
The Alphabet is vowel  

Flowchart:

Flowchart: Check whether an alphabet is vowel or consonant

C# Sharp Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a C# Sharp program to check whether a triangle can be formed by the given value for the angles.
Next: Write a C# Sharp program to calculate profit and loss on a transaction.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming