Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a program that uses a recursive function to print a string backward. Do no

ID: 3553681 • Letter: W

Question

 write a program that uses a recursive function to print a string backward. Do not use 
 any global variables; use the appropriate parmaters. Yor main program my looks along the  
 lines of: 
 #include<iostream> #include<string> using namespace std; void printReverse(string str); void printStringReverse(string str, int pos, int length);  int main() {         string str = "somestring"; 
          cout<<"length is: "<<str.length()<<endl; 
          cout<<str<<"printed backward is:";         printReverse(str);         cout<<endl;         return 0; }  
void printReverse(string str) { // your code goes here
} void printReverse(string str) { // your code goes here
}

Explanation / Answer

#include<stdio.h> #include<string.h>

void printReverse(char *str);



int main()
{
char str[100] = "somestring";

printf("length is: ",strlen(str));

printf("printed backward is:");
printReverse(str);
return 0;
}

void printReverse(char *str)
{
if(*str)
{
printReverse(str+1);
printf("%c",*str);
}
}