Write a C++ recursive function that takes an array of words and returns an array
that contains all the words capitalized
#include <iostream>
#include <cctype>
#include <string>
using namespace std;
string str = "";
string toUp(string s) {
if (s.length() == 0) {
return str;
}
else {
char c = toupper(s[0]);
str += c;
s.erase(0, 1);
toUp(s);
}
return str;
}
int main() {
string s = "qwerty Hello PPpp";
cout << toUp(s);
return 0;
}
Comments
Leave a comment