एक स्ट्रिंग को एक निश्चित संख्या में संयोजित करने के लिए एक प्रोग्राम n के मान के आधार पर स्ट्रिंग कॉन्टेनेट विधि n कई बार चलाएगा।
परिणाम स्ट्रिंग को कई बार दोहराया जाएगा।
उदाहरण
given string: “ I love Tutorials point” n = 5
आउटपुट
I love Tutorials pointI love Tutorials pointI love Tutorials pointI love Tutorials point I love Tutorials point
आउटपुट देखने के बाद साफ हो जाता है कि फंक्शन क्या करेगा।
उदाहरण
#include <iostream>
#include <string>
using namespace std;
string repeat(string s, int n) {
string s1 = s;
for (int i=1; i<n;i++)
s += s1; // Concatinating strings
return s;
}
// Driver code
int main() {
string s = "I love tutorials point";
int n = 4;
string s1 = s;
for (int i=1; i<n;i++)
s += s1;
cout << s << endl;;
return 0;
} आउटपुट
I love tutorials pointI love tutorials pointI love tutorials pointI love tutorials point