Cranes at VIIT Q5
Count Vowels and Consonants in a String
Write a C program that counts the number of vowels and consonants in a given string.
Problem Statement:
-
Given a string s consisting of uppercase and lowercase English alphabets, count and print:
- The number of vowels in the string.
- The number of consonants in the string.
- Ignore any non-alphabetic characters.
Input Format:
- s: A string containing uppercase and lowercase alphabets.
Output Format:
- Print the number of vowels and consonants in the string.
Example Inputs & Outputs:
Enter the string: Hello World
Vowels: 3
Consonants: 7
Enter the string: C Programming
Vowels: 3
Consonants: 9
Constraints:
Hint:
To solve this problem, follow these steps:
-
Iterate Through the String:
- Use a loop to go through each character of the string.
- Check if the character is a letter using the isalpha() function.
-
Check for Vowels and Consonants:
-
Ignore Non-Alphabetic Characters:
- Use the isalpha() function to check if the character is a letter.
-
Print the Count:
- Print the final count of vowels and consonants.
Formula Breakdown:
Task: Implement the above logic and write a C program to count the number of vowels and consonants in a string.