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

Answer Posted / shivaraj

main()
{
char str[10];
cin>>str;
int len=strlen(str);
reverse(len);
cout<<"Reversed string is: "<<str;
}

void reverse(int len)
{
static int i=0;
str[i]=str[len-1]; //put the char in last pos to first pos
for(j=len-1;j>i;j--)
str[j]=str[j-1]; //shift to right
i++;

if(i==len)
return;

reverse(len);
}

Is This Answer Correct ?    5 Yes 15 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is action and transformation in spark?

592


What is the difference between #include

and #include “header file”?

544


please help me..... please codes and flowchart plz turbo c lang po yan.....please asap response... 3. Make an astrology program. The user types in his or her birthday (month, day, and year as integer), and the program responds with the user’s zodiac sign, horoscope, and other information related to it. If the user’s birth year falls into a leap year, your program should display an appropriate message for it. NOTES: Conditional Statements: it should be with graphics

2854


What are different storage class specifiers in c?

611


What is meant by recursion?

628






What is malloc return c?

596


Explain about the functions strcat() and strcmp()?

596


What is an arrays?

648


Can you explain the four storage classes in C?

639


What is the difference between near, far and huge pointers?

628


What are structural members?

566


Why is c so popular?

644


code for replace tabs with equivalent number of blanks

1631


What are control structures? What are the different types?

592


What is the difference between malloc() and calloc()?

613