C Exercises: Reverse a string partially
2. Reverse Substring
Write a C program that takes a string and two integers (n1, n2). Now reverse the sequence of characters in the string between n1 and n2.
Let l be the length of the string.
Constraints:
- 1 ≤ n1 ≤ n2 ≤ l ≤100
- Each letter of the string is an uppercase or lowercase letter.
Sample Date:
("abcdxyabcd", 5, 6) -> "abcdyxabcd"
("Exercises", 1, 3) -> "exercises"
C Code:
Output:
Input a string: Input position-1 for reverse the string: abcdxyabcd 5 6 Input position-2 for reverse the string: Reverse string (partly): abcdyxabcd
Flowchart:
For more Practice: Solve these Related Problems:
- Write a C program to reverse a substring between two indices of a given string without using library functions.
- Write a C program that uses pointer arithmetic to reverse the portion of a string delimited by two user-supplied indices.
- Write a C program to swap the characters between two positions in a string so that the segment is reversed in place.
- Write a C program to reverse a substring and then check if the modified string forms a palindrome.
C Programming Code Editor:
Previous C Programming Exercise: Find the integer that appears the least often.
Next C Programming Exercise: Second largest among three integers.
What is the difficulty level of this exercise?
Based on 136 votes, average difficulty level of this exercise is Hard
.
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics