Interview Questions   Tutorials   Discussions   Programs   

C - How to reverse a string using a recursive function, without swapping or using an extra memory?




299
views
asked marvit August 18, 2014 06:23 AM  

How to reverse a string using a recursive function, without swapping or using an extra memory?


           

1 Answers



 
answered By bhjahnavi   0  
/* to reverse a string using a recursive function, without swapping or using an extra memory*/
#include<stdio.h>
void reverse(char *,int b);
void main()
{
char a[26];
int len;
clrscr();
printf("enter string ");
gets(a);
len=strlen(a);
reverse(a,len);
getch();
}
void reverse(char * a,int len)
{
if(len==0)
printf("%c",a[len]);
else
{
printf("%c",a[len]);
reverse(a,len-1);
}
} 
output:
enter string: reverse
esrever
flag   
   add comment

Your answer

Join with account you already have

FF

Preview


Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!

Alert