diff --git a/reverse b/reverse new file mode 100644 index 0000000..a3c6642 --- /dev/null +++ b/reverse @@ -0,0 +1,31 @@ +#include +#include + +// declaring recursive function +char* reverse(char* str); + +void main() +{ + int i, j, k; + char str[100]; + char *rev; + printf("Enter the string:\t"); + scanf("%s", str); + printf("The original string is: %s\n", str); + rev = reverse(str); + printf("The reversed string is: %s\n", rev); + getch(); +} + +// defining the function +char* reverse(char *str) +{ + static int i = 0; + static char rev[100]; + if(*str) + { + reverse(str+1); + rev[i++] = *str; + } + return rev; +}