Count Number of Vowels and Consonants in a String
Here you will get the program code of C++ program to count number of vowels and consonants in a string.
Program Code to Count Number of Vowels and Consonants in a String
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #include<iostream> using namespace std; int main() { char ch[100]; int i=0,vowel=0,consonant=0; cout<<"Enter a string to check vowel or consonant : "; cin>>ch; while(ch[i]!='\0') { switch(ch[i]) { case 'a': vowel++;break; case 'e': vowel++;break; case 'i': vowel++;break; case 'o': vowel++;break; case 'u': vowel++;break; case 'A': vowel++;break; case 'E': vowel++;break; case 'I': vowel++;break; case 'O': vowel++;break; case 'U': vowel++;break; default: consonant++; break; } i++; } cout<<"\nNumber of Vowels are : "<<vowel; cout<<"\nNumber of Consonants are : "<<consonant; return 0; } |
Output
Enter an Alphabet to check vowel or consonant : CodeRevise
Number of Vowels are : 5
Number of Consonants are : 5
Check out our other C++ programming Examples