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

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

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]!='';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 "<
Positive: 44 %
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 ).
Positive: 38 %
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.
Positive: 18 %

C Programming Examples on Strings. ... They count the number of vowels ... C Program to Reverse every Word of given String C Program to Count the Number ...
Positive: 44 %
... that counts number of words in a given string ... number of words in a given string..... in C ... string; Write a shell program to count number ...
Positive: 39 %
... find the sum of individual digits of a positive ... a C program to determine if the given string is a ... Write a C program to count the ...