C++ Exercises: Create a new string using two given strings s1, s2, the format of the new string will be s1s2s2s1
C++ Basic Algorithm: Exercise-57 with Solution
Write a C++ program to create a new string using two given strings s1, s2, the format of the new string will be s1s2s2s1.
Sample Solution:
C++ Code :
#include <iostream>
using namespace std;
string test(string s1, string s2)
{
return s1 + s2 + s2 + s1;
}
int main()
{
cout << test("Hi", "Hello") << endl;
cout << test("whats", "app") << endl;
return 0;
}
Sample Output:
HiHelloHelloHi whatsappappwhats
Pictorial Presentation:
Flowchart:
C++ Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a C++ program to check three given integers (small, medium and large) and return true if the difference between small and medium and the difference between medium and large is same.
Next: Write a C++ program to insert a given string into middle of the another given string of length 4.
What is the difficulty level of this exercise?