Write a recursive function to reverse the string.
#include<stdio.h> #include<string.h> void Reverse_string_Rec(char*,char*); int main() { char s[50]; printf("Enter the string : "); scanf("%[^\n]",s); printf("%s\n",s); Reverse_string_Rec(s,&s[(strlen(s)-1)]); printf("%s\n",s); return 0; } void Reverse_string_Rec(char*p,char*q) { char temp; if(p < q) { temp = *p,*p = *q,*q = temp; Reverse_string_Rec(p+1,q-1); } }
Output
Enter the string : nraeL oT toL nraeL oT toL Lot To Learn