Write a program to count number of vowels in a given string.
1
Expert's answer
2011-07-11T09:54:29-0400
#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; }
Comments
Leave a comment