C program to swap adjacent characters of a String
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:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.