Solution 12 to 25
Solution 22

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

  1. Start
  2. Initialize a counter for vowels (n) to 0.
  3. Read the string input from the user.
  4. 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).
  5. Print the number of vowels counted.
  6. 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