C Program to Reverse String using Recursion
Write a Program to Reverse String using Recursion
// C Program to Reverse String using Recursion #include <stdio.h> void reverse_string(char S[], int i, int l) { char temp; temp = S[i]; S[i] = S[l - i]; S[l - i] = temp; if(i == l / 2) { return; } reverse_string(S, i + 1, l); } int main() { char S[50]; printf("Enter String :--> "); gets(S); int l = strlen(S); reverse_string(S, 0, l - 1); printf("Reverse String :--> %s", S); return 0; }
Output:
Enter String :--> CodeCrucks
Reverse String :--> skcurCedoC