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
What is action and transformation in spark?
What is the difference between #include
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
What are different storage class specifiers in c?
What is meant by recursion?
What is malloc return c?
Explain about the functions strcat() and strcmp()?
What is an arrays?
Can you explain the four storage classes in C?
What is the difference between near, far and huge pointers?
What are structural members?
Why is c so popular?
code for replace tabs with equivalent number of blanks
What are control structures? What are the different types?
What is the difference between malloc() and calloc()?