Write a program to count number of vowels in a given string.
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char str[] = "hello, world!";
int vowels_ctr = 0;
for (char *it = str; *it; ++it) {
& switch (*it) {
& case 'a': case 'A':
& case 'e': case 'E':
& case 'o': case 'O':
& case 'i': case 'I':
& case 'u': case 'U':
& ++vowels_ctr;
& }
}
cout << "The number of vowels in <" << str << "> is " << vowels_ctr << endl;
return 0;
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
C++