C program to reverse a string using recursion.
source code
#include<stdio.h>
#define MAX 100
char* getReverse(char[]);
int main()
{
char str[MAX],*rev;
printf("Enter any string: ");
scanf("%s",str);
rev = getReverse(str);
printf("Reversed string is: %s",rev);
getch();
return 0;
}
char* getReverse(char str[])
{
static int i=0;
static char rev[MAX];
if(*str)
{
getReverse(str+1);
rev[i++] = *str;
}
return rev;
}
Comments
Post a Comment