Computer Science, asked by kumarsidhartha, 4 months ago

Write a function which accepts a string and if length of the string

is even it returns a string in which 1st character swapped with

2nd, 3rd character with 4th character and so on, otherwise return

a message “Illegal string”.

E.g. S =”python” than output : “yphtno”​

Answers

Answered by CdtRaghib
3

Explanation:

string fuction(string x)

{

if (x.size()%2==0)

{

for (int i=0, index=1;i<x.size();i+=2,index+=2)

//Using the C++ swap function

swap(x[i],x[index]);

return x;

}

else return "Illegal string";

}

I hope this will help you. Please mark me as the brainliest.

Similar questions