Challenge: Vowel Counter
Completed
Read one line of text and print how many vowels (a e i o u, small or capital) it contains.
Input
One line of text (up to 200 characters).
Output
The number of vowels.
Example
Input
Hello World
Output
3
Editor
C
Hints
Read the line with fgets.
Use tolower so you only have to check small vowels.
Solution explanation
Turning each character to lower case first means we only need to compare against five letters.
Show solution
#include <stdio.h>
#include <ctype.h>
int main() {
char line[201];
fgets(line, 201, stdin);
int count = 0;
for (int i = 0; line[i] != '\0'; i++) {
char c = tolower(line[i]);
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
count++;
}
}
printf("%d\n", count);
return 0;
} Output
Answer
You can practice without logging in. Log in to save completion.
Save your progress
You're practising as a guest, so your progress won't be saved.
- Track every lab you complete
- Earn verifiable lab certificates
- See your progress in every module