This program will help beginners to calculate number of vowels in a given string. Please note that you need to take care of both uppercase and lowercase letters.
C# Code Example to Calculate Vowels:
using System;
namespace MyApp
{
class vowels_class
{
static void Main()
{
int my_count = 0;
Console.WriteLine("Enter a string:");
string myString = Console.ReadLine();
foreach (char ch_vowel in myString)
{
switch (ch_vowel)
{
case 'a':
case 'A':
my_count++;
break;
case 'e':
case 'E':
my_count++;
break;
case 'i':
case 'I':
my_count++;
break;
case 'o':
case 'O':
my_count++;
break;
case 'u':
case 'U':
my_count++;
break;
default:
break;
}
}
Console.WriteLine("Number of Vowels are: {0} ", my_count);
Console.Read();
}
}
}
No comments:
Post a Comment