Wednesday, 23 April 2014

C# program to check whether a input character is vowel or not

There are five vowels in English alphabets there are A,E,I,O,U. All these vowels comes in alphabets where their place differs from each other. Letter A comes in first position, E comes in 5th position of English alphabet so on, now we need to determine only vowels in alphabets. As there are limited number of options available to get result hence we choose switch case to solve this problem. 

Let's start with programming aspect here we write a c# program to check whether a input character is vowel or not using switch statement. Declare a string and get input by asking user so that we get a input. Now we add switch statement where if there any capital letter then we filter those things by using str.Tolower where we only get lower case letter hence it is useful for us to determine a vowel or not. You can do with capital letters if you want but in the next we can see that I have mentioned lower letters in switch cases as case1= a, case2=e,..etc. There are five cases to check input character is vowel of not, if this matches then say "vowel found" or say "vowel not found". For both of statements add break at last so that one can get exact output which is needed.

C# is an object oriented language hence we create an object to call the class switch1 which we have written our program. Call the class in main program as switch1 s = new switch1() in this class we wrote a code inside the method so using "s" object call the method s.switchcase1(). Now the our c# program to check vowel or not program is ready run, if you get any difficulties then post a comment here.


 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Text;  
 namespace switchcase1  
   class switch1  
     public void switchcase1()  
       string str = "";  
       Console.WriteLine("\nEnter a character to check vowel or not");  
       str = Console.ReadLine();  
       switch (str.ToLower())  
         case "a":  
         case "e":  
         case "i":  
         case "o":  
         case "u":  
           Console.WriteLine("Not a Vowel");  
     class Program  
       static void Main(string[] args)  
         switch1 s = new switch1();  


 Enter a character to check vowel or not  
 its a vowel  

1 comment:
Write comments
  1. I like the way explained here which is easy to understand


Featured post

List of Universities in Karnataka offering M.Sc Computer Science

The post-graduate programme in Computer Science (M.Sc Computer Science) contains two academic years duration and having a four semesters....

Popular Posts

Copyright @ 2011-2016