Recursive Upper Function

Problem

Write a C++ recursive function to convert a character string into capital letters.

Solution

Instead of looping in the string character by character we can recursively call a function while advancing an index each time. Once the index reaches the end of the string we stop recursion. Converting a letter into capital case in C++ is simply achieved by adding the difference between any capital letter and its small letter ASCII value to the ASCII code of the character that we need to convert. Please refer to the code below for more details.

Code

Here is the C++ code to do that

Add a Comment

Your email address will not be published. Required fields are marked *