Below program counts number of vowels in a string using C#.NETSimple Program:using System;
namespace DotNetMirror
{
class CountNumberOfVowels
{
static void Main()
{
int vowelsCount = 0;
Console.WriteLine("Please enter string value to count no of vowels in it:");
string strValue = Console.ReadLine();
for (int j = 0; j < strValue.Length; j++)
{
if (strValue[j] == 'a' || strValue[j] == 'A' || strValue[j] == 'e' || strValue[j] == 'E' || strValue[j] == 'i' || strValue[j] == 'I' || strValue[j] == 'o' || strValue[j] == 'O' || strValue[j] == 'u' || strValue[j] == 'U')
{
vowelsCount++;
}
}
Console.WriteLine("No of vowels in [{0}] are {1}" , strValue, vowelsCount);
Console.ReadLine();
}
}
} Output:
|