Answer to Question #3318 in C++ for mukunda

Question #3318
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;
}

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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS