FIND THE ANSWERS

Write a c++ program to count the number of vowels in a given string with algorithm and flowchart?

Answer this question

  • Write a c++ program to count the number of vowels in a given string with algorithm and flowchart?


Answers

Answer #1 | 10/02 2014 17:11
#include #include void main() { char str[20]; int count=0; cout<<"Enter the string"; gets(str); for(int i=0;str[i]!='\0';i++) { if(str[i]=='A'||str[i]=='E'||str[i]=='I'||str[i]=='O'||str[i]=='U'||str[i]=='a'|| str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u') count++; } cout<<"The number of vowels in the string "<
Answer #2 | 10/02 2014 08:40
Well, in C++ and C strings are just arrays of chars. The array of chars uses the subscript operator([]) to access the char in the array. Simply loop through the string and check each char, if it's a vowel then do the work if it's a vowel, otherwise it's not. Eg for C++: // Loop through it. for(unsigned int x = 0; x < myString.length(); ++x){ if(myString[x] == 'a' || myString[x] == 'i') { // add more vowels if needed // ... } } If you're using cstrings(const char* or char*) you must use C functions. strlen, strcmp, etc. If using C++ it's recommended to use the std::string(found in ).
Answer #3 | 10/02 2014 07:49
Simply loop through the string (remember, a string can be treated like an array of characters). If the char matches a, e, i, o or u, increment a vowel counter and continue.

Possible answer