logo CodeStepByStep logo

switchPairs

Language/Type: C++ string return
Related Links:

Write a function named switchPairs that accepts a string as a parameter and returns that string with each pair of neighboring letters reversed. If the string has an odd number of letters, the last letter should not be modified. For example, the call switchPairs("example") should return "xemalpe" and the call switchPairs("hello there") should return "ehll ohtree".

Function: Write a C++ function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.