Why Choose Us?
0% AI Guarantee
Human-written only.
24/7 Support
Anytime, anywhere.
Plagiarism Free
100% Original.
Expert Tutors
Masters & PhDs.
100% Confidential
Your privacy matters.
On-Time Delivery
Never miss a deadline.
Write a program that uses a recursive function to print a string backwards
Write a program that uses a recursive function to print a string backwards. Your program must contain a recursive function that prints the string backwards. Do not use any global variables; use appropriate parameters.
Expert Solution
The problem:
Write a program that uses a recursive function to print a string backwards. Your program must contain a recursive function that prints the string backwards. Do not use any global variables; use appropriate parameters.
The solution:
#include <iostream>
#include <string> //used for string operations
using namespace std;
void strBack(char *s, int i){
if (i<0) return; //base case, terminates when the length of the string is 0
else { //general case
cout << *(s+i); //just print the character at length position i from starting position s
strBack(s, i-1); //recusrively call with one less character (at the right)
}
}
int main(){
char *str = "Hello World!";
strBack(str, strlen(str));
return 0;
}
Archived Solution
You have full access to this solution. To save a copy with all formatting and attachments, use the button below.
For ready-to-submit work, please order a fresh solution below.





