Given an input string, output the reverse of the string using "recursion".
For example:
If the given string is , coderegister
Then the output is , retsigeredoc
Input:
coderegister
Output:
retsigeredoc
C Implementation:
For example:
If the given string is , coderegister
Then the output is , retsigeredoc
Input:
coderegister
Output:
retsigeredoc
C Implementation:
#include<stdio.h>
#include <string.h>
void swap(char *x,char *y)
{
char temp = *x;
*x = *y;
*y = temp;
}
void reverse(char s[],int i,int j)
{
if(i>j)
return;
swap((s+i),(s+j));
reverse(s,i+1,j-1);
}
int main()
{
char s[1000000];
scanf("%s",s);
reverse(s,0,strlen(s)-1);
printf("%s",s);
return 0;
}