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
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
English,
1 month ago
Math,
1 month ago
Accountancy,
4 months ago
History,
4 months ago
English,
10 months ago