31 lines
629 B
C
Raw Normal View History

2023-12-18 21:37:02 +01:00
#include <stdio.h>
#include <string.h>
void reverseString(char *str, int start, int end) {
// Base case: if start index is greater or equal to end index
if (start >= end) {
return;
}
// Swap the characters at start and end
char temp = str[start];
str[start] = str[end];
str[end] = temp;
// Recursive call with modified indices
reverseString(str, start + 1, end - 1);
}
int main() {
char str[] = "Hello, World!";
int n = strlen(str);
printf("Original string: %s\n", str);
// Call the reverseString function
reverseString(str, 0, n - 1);
printf("Reversed string: %s\n", str);
return 0;
}