Question: Using C++ /* Write a recursive method that takes as parameters a String s and an integer i and returns a String that has s

Using C++

/* Write a recursive method that takes as parameters a String s and an integer i and returns a String that has s repeated i times. For example, if the given string is "Go bears! " and the integer is 3 then the return value would be "Go bears! Go bears! Go bears! ". (Note that if the integer is 0, then the empty string "" should be returned.) */ string repeat(string s, unsigned int i);

------------------------------------------------------------------------

This is what I have so far:

string repeat(string s, unsigned int i)

{

if (i >0)

{

return s + ""+ repeat(s, i-1);

else

return "";

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!