Answer to Question #318660 in C++ for ann

Question #318660

#include <iostream>

#include <cstring>

using namespace std;


#define STR_MAX_SIZE 100


void preserveString(char*, int);


int main(void) {

  char str[STR_MAX_SIZE];


  cout << "Enter string: ";

  fgets(str, STR_MAX_SIZE, stdin);


  preserveString(str, strlen(str));


  return 0;

}


void preserveString(char *str, int size) {

  if(size > 0) {

    for(int i = 0; i < size - 1; i++) {

      cout << str[i];   

  }

    cout << endl;

     

    


    // TODO: Add the recursive case of the function here

  }

}



please help me to add the recursive function thankyou


1
Expert's answer
2022-03-26T12:40:46-0400
#include <iostream>
#include <cstring>
using namespace std;


#define STR_MAX_SIZE 100


void preserveString(char*, int);


int main(void) {
    char str[STR_MAX_SIZE];


    cout << "Enter string: ";
    fgets(str, STR_MAX_SIZE, stdin);


    preserveString(str, strlen(str));


    return 0;
}


void preserveString(char *str, int size) {
    if(size > 0) {
        for(int i = 0; i < size - 1; i++) {
            cout << str[i];   
        }
        cout << endl;


    // recursive case of the function here
    preserveString(str, size-1);
  }


}

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
APPROVED BY CLIENTS