Given a string, reverse the string recursively calling the reverse function without swapping the characters of the string
#include <stdio.h> #include <string.h> #include <stdlib.h> #define MAX 256 /* Recursive function to reverse the given string */ void reverse(char *s) { /* If the end of the string is reached, return */ if(*s=='\0') return; /* Call the function recursively , skipping a character every time the function is called */ reverse((s+1)); /* Print the character from the recursive stack */ printf("%c",*s); } /* Main function */ int main(void) { char *s; /* Dynamically allocate the memory to get the input string */ s=(char*)malloc(sizeof(char)*MAX); /* Get the input string from the user */ scanf("%s",s); /* Recursively call the function to print the reverse of the string */ reverse(s); return 0; }