Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

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  

Pictorial Presentation:

Conditional Statement: Check whether an alphabet is vowel or consonant.

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?

Test your Programming skills with w3resource's quiz.