http://www.allinterview.com/showanswers/16431.html
/* Following code does as intended */
#include <stdio.h>
#define REVERSE_STRING(X) Rstring(X, *(X), strlen(X)-1)
void Rstring( char *str, char c, int index )
{
if( index != 0 )
Rstring( str, *(str+(strlen(str))-index),
index-1);
*(str+index) = c;
}
int main( void )
{
char str[] = "Dharmendra Patel";
printf("Actual string is [%s]\n", str);
REVERSE_STRING(str);
printf("Reversed string is [%s]\n", str);
return 0;
}
Can you pls explain, when recursive function is useful?
ReplyDelete