Given a string str, the task is to swap adjacent characters of this string in C.
Input: str = "geeks" Output: NA Not possible as the string length is odd Input: str = "geek" Output: egke
- Check if the length of the string is even or odd.
- If the length is odd, swapping cannot be done.
- If the length is even, take each character of the string one by one and swap it with the adjacent character.
Below is the implementation of the above approach:
Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.