C++
Write a recursive routine that will have a character array and an
index as parameters and will return the count of all vowels (assume
lowercase).
You may assume that the index starts out at the END of the
array.
#include <iostream> using namespace std; int count_vowels(char array[], int index); int main() { char arr[] = {'H', 'e', 'l', 'l', 'O'}; cout << count_vowels(arr, 4) << endl; return 0; } int count_vowels(char array[], int index) { if (index < 0) { return 0; } else { int count = count_vowels(array, index - 1); char ch = array[index]; if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') ++count; return count; } }
Get Answers For Free
Most questions answered within 1 hours.