programming-examples/c/Recursion/C Program to Reverse a string by recursion.c

23 lines
435 B
C
Raw Normal View History

2019-11-15 12:59:38 +01:00
#include<stdio.h>
#define MAX 100
char* reverse(char[]);
int main()
{
char str[MAX],*rev;
printf("Enter any string: ");
scanf("%s",str);
rev = reverse(str);
printf("Reversed string is: %s",rev);
return 0;
}
char* reverse(char str[])
{
static int i=0;
static char rev[MAX];
if(*str)
{
reverse(str+1);
rev[i++] = *str;
}
return rev;
}