Counting Vowels in a String
This program reads a string from the user and counts the number of vowels in that string. It handles both uppercase and lowercase vowels. The goal is to help you understand how to process strings and count specific characters using simple control structures in C.
Code Breakdown
Algorithm
- Start
- Initialize a counter for vowels (
n
) to 0. - Read the string input from the user.
- Iterate through each character of the string:
- Check if the character is a vowel (
a, e, i, o, u
in both uppercase and lowercase). - If it is a vowel, increment the counter (
n
).
- Check if the character is a vowel (
- Print the number of vowels counted.
- End
Code Explanation
Example Flowchart
Start
|
V
Initialize `n` to 0
|
V
Read string input
|
V
For each character in the string:
|
|--- Is character a vowel? ---- Yes ----> Increment `n`
| |
| No
|
V
Print the number of vowels
|
V
End