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
Get step-by-step solutions from verified subject matter experts
