Answer to Question #300358 in C++ for Adi

Question #300358

Given a string, write a recursive function to find its first uppercase letter. Your function should

return the letter.

Function Prototype: char findUppercase(char* str);


1
Expert's answer
2022-02-20T14:40:18-0500
#include <iostream>
using namespace std;

char findUppercase(char* str) {
    if (str[0] == '\0') {
        return '\0';
    }
    if (str[0] >= 'A' && str[0] <= 'Z') {
        return str[0];
    }

    return findUppercase(str+1);
}

int main() {
    char str[] = "this is a Test string";

    cout << "The first uppecase letter is \'"
         << findUppercase(str) << "\'";

    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