Program to count the number of vowels in a word Last Updated : 18 Jan, 2024 Comments Improve Suggest changes Like Article Like Report 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', 'i'). Input: "HELLO"Output: 2Explanation: The word "HELLO" has two vowels ('E', 'O'). Approach: To solve the problem, follow the below idea: Iterate through each character in the given word and check if it is a vowel. If it is, increment the count. Step-by-step algorithm: Initialize a variable vowelCount to 0 to keep track of the number of vowels.Iterate through each character in the word.Check if the character is a vowel (either uppercase or lowercase).If it is a vowel, increment vowelCount.After iterating through all characters, vowelCount will contain the total count of vowels.Below is the implementation of the algorithm: C++ #include <iostream> using namespace std; int main() { char word[] = "programming"; int vowelCount = 0; for (int i = 0; word[i] != '\0'; ++i) { if (word[i] == 'a' || word[i] == 'e' || word[i] == 'i' || word[i] == 'o' || word[i] == 'u' || word[i] == 'A' || word[i] == 'E' || word[i] == 'I' || word[i] == 'O' || word[i] == 'U') { ++vowelCount; } } cout << "Number of vowels: " << vowelCount << endl; return 0; } C #include <stdio.h> int main() { char word[] = "programming"; int vowelCount = 0; for (int i = 0; word[i] != '\0'; ++i) { if (word[i] == 'a' || word[i] == 'e' || word[i] == 'i' || word[i] == 'o' || word[i] == 'u' || word[i] == 'A' || word[i] == 'E' || word[i] == 'I' || word[i] == 'O' || word[i] == 'U') { ++vowelCount; } } printf("Number of vowels: %d\n", vowelCount); return 0; } Java public class VowelCount { public static void main(String[] args) { String word = "programming"; int vowelCount = 0; for (int i = 0; i < word.length(); i++) { char currentChar = word.charAt(i); if (currentChar == 'a' || currentChar == 'e' || currentChar == 'i' || currentChar == 'o' || currentChar == 'u' || currentChar == 'A' || currentChar == 'E' || currentChar == 'I' || currentChar == 'O' || currentChar == 'U') { vowelCount++; } } System.out.println("Number of vowels: " + vowelCount); } } Python3 word = "programming" vowel_count = 0 for char in word: if char.lower() in ['a', 'e', 'i', 'o', 'u']: vowel_count += 1 print("Number of vowels:", vowel_count) C# using System; class Program { static void Main() { string word = "programming"; int vowelCount = 0; foreach(char c in word) { if ("aeiouAEIOU".Contains(c)) { vowelCount++; } } Console.WriteLine("Number of vowels: " + vowelCount); } } JavaScript let word = "programming"; let vowelCount = 0; for (let i = 0; i < word.length; i++) { let currentChar = word[i]; if ('aeiouAEIOU'.includes(currentChar)) { vowelCount++; } } console.log("Number of vowels:", vowelCount); OutputNumber of vowels: 3 Time Complexity: O(N), where N is the length of the input word.Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Program to count the number of vowels in a word S srinam Follow Improve Article Tags : DSA Similar Reads 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 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 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 Lex Program to count number of words Lex is a computer program that generates lexical analyzers and was written by Mike Lesk and Eric Schmidt. Lex reads an input stream specifying the lexical analyzer and outputs source code implementing the lexer in the C programming language. Prerequisite: Flex (Fast lexical Analyzer Generator) Examp 1 min read C program to count number of vowels and consonants in a String Given a string and write a C program to count the number of vowels and consonants in this string. Examples: Input: str = "geeks for geeks" Output: Vowels: 5 Consonants: 8 Input: str = "abcdefghijklmnopqrstuvwxyz" Output: Vowels: 5 Consonants: 21Using For LoopsTake the string as inputTake each charac 4 min read Like