C# Program to Count Number of Vowels and Consonants in a Given String Last Updated : 07 Jan, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report C# is a general-purpose programming language it is used to create mobile apps, desktop apps, web sites, and games. As we know that a, e, i, o, u are vowels, and the remaining alphabet is known as a consonant in English so now using C# language we will create a program that will return us the total number of vowels and consonants present in the given string. Example: Input: geeksforgeeks Output: Total number of vowels = 5 Total number of consonants = 8 Input: HelloGFG Output: Total number of vowels = 2 Total number of consonants = 6 Approach: To print the total number of Vowels and consonants from a given String we use the following approach: Store the string using string datatype.Declare two variables to count the number of vowels and consonants.Now using the length property find the length of the given stringNow iterate the string from left to right and check if the character is either vowel or a consonant.If the character encountered is a vowel increase the count of vowel else increases the count of consonant. Example 1: C# // C# program to print the total number of Vowels // and consonants from a given string using System; class GFG{ public static void Main() { string inputstring; int i, len, vowels, consonants; inputstring = "geeksforgeeks"; vowels = 0; consonants = 0; len = inputstring.Length; // Iterating the string from left to right for(i = 0; i < len; i++) { // Check if the character is a vowel if (inputstring[i] == 'a' || inputstring[i] == 'e' || inputstring[i] == 'i' || inputstring[i] == 'o' || inputstring[i] == 'u' || inputstring[i] == 'A' || inputstring[i] == 'E' || inputstring[i] == 'I' || inputstring[i] == 'O' || inputstring[i] == 'U') { // Increment the vowels vowels++; } // Check if the character is a alphabet // other than vowels else if ((inputstring[i] >= 'a' && inputstring[i] <= 'z') || (inputstring[i] >= 'A' && inputstring[i] <= 'Z')) { // Increment the consonants consonants++; } } // Display the count of vowels and consonant Console.WriteLine("count of vowel = " + vowels); Console.WriteLine("count of consonant = " + consonants); } } Outputcount of vowel = 5 count of consonant = 8 Example 2: C# // C# program to print the total number of Vowels // and consonants from a given string using System; class GFG{ public static void Main() { char[] inputstring = new char[100]; int i, vowels, consonants, x; vowels = 0; consonants = 0; // Enter the length of the string Console.WriteLine("Please enter the length of the string:\n"); x = int.Parse(Console.ReadLine()); // Enter the string Console.WriteLine("Enter string:\n"); for (i = 0; i < x; i++) { inputstring[i] = Convert.ToChar(Console.Read()); } // Iterating the string for (i = 0; inputstring[i] != '\0'; i++) { // Check if the character is a vowel if (inputstring[i] == 'a' || inputstring[i] == 'e' || inputstring[i] == 'i' || inputstring[i] == 'o' || inputstring[i] == 'u' || inputstring[i] == 'A' || inputstring[i] == 'E' || inputstring[i] == 'I' || inputstring[i] == 'O' || inputstring[i] == 'U') { // Increment the vowels vowels++; } else { // Increment the consonants consonants++; } } // Display the count of vowels and consonant Console.WriteLine("\ncount of vowel = " + vowels); Console.WriteLine("count of consonant = " + consonants); Console.ReadLine(); Console.ReadLine(); } } Output: Please enter the length of the string: 6 Enter string: HeyGFG count of vowel = 1 count of consonant = 5 Comment More infoAdvertise with us Next Article Java Program to Count the Total Number of Vowels and Consonants in a String P pulamolusaimohan Follow Improve Article Tags : C# CSharp-programs CSharp-Strings-Programs Similar Reads Program to count the number of consonants in a word Write a program to count the number of consonants in a given word. Consonants are the letters of the English alphabet excluding vowels ('a', 'e', 'i', 'o', 'u'). Examples: Input: "programming"Output: 8 Explanation: The eight consonants are: 'p', 'r', 'g', 'r', 'm', 'm', 'n', 'g') Input: "hello"Outpu 5 min read R Program to Count the Number of Vowels in a String In this article, we will discuss how to Count the Number of Vowels in a String with its working example in the R Programming Language. It is a fundamental in programming that allows us to repeatedly execute a block of code as long as a specified condition remains true. It's often used for tasks like 5 min read Program to count the number of vowels in a word Write a program to count the number of vowels in a given word. Vowels include 'a', 'e', 'i', 'o', and 'u' (both uppercase and lowercase). The program should output the count of vowels in the word. Examples: Input: "programming"Output: 3Explanation: The word "programming" has three vowels ('o', 'a', 3 min read Program to count the number of characters in a word Write a program to count the number of characters in a word. Examples: Input: Word: "programming"Output: 11 Input: Word: "hello"Output: 5 Approach: To solve the problem, follow the below idea: To count the number of characters in a word, maintain a variable to count all the characters. Iterate throu 2 min read Java Program to Count the Total Number of Vowels and Consonants in a String Given a String count the total number of vowels and consonants in this given string. Assuming String may contain only special characters, or white spaces, or a combination of all. The idea is to iterate the string and checks if that character is present in the reference string or not. If a character 2 min read Java Program to Count Number of Vowels in a String In java, the string is a sequence of characters and char is a single digit used to store variables. The char uses 2 bytes in java. In java, BufferedReader and InputStreamReader are used to read the input given by the user from the keyboard. Then readLine() is used for reading a line. The java.io pac 4 min read Like