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

Answer Posted / osama al-ahmad

#include <iostream>
#include < string >
using namespace std;
int i=0;
int z=0;
int count=0;
int Length(string name)
{
if (name[i] == '\0')
return count;
else
{
count++;
i++;
return Length(name);
}

}
char Print_B(string name)
{
if (z == Length(name))
return name[z];
else
{
z++;
cout<<name[count];
count--;
return Print_B(name);
}
}
void main()
{
string name;
cin>>name;
cout<<"Name : ";
Length(name);
cout<<Print_B(name);
}

Is This Answer Correct ?    4 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

List the difference between a 'copy constructor' and a 'assignment operator' in C?

642


write a program fibonacci series and palindrome program in c

633


What is meant by initialization and how we initialize a variable?

590


How to delete a node from linked list w/o using collectons?

2091


What is a pointer and how it is initialized?

611






Write a program to reverse a string.

644


Explain indirection?

650


What is main return c?

522


Write the control statements in C language

653


Explain what header files do I need in order to define the standard library functions I use?

649


What is the difference between functions abs() and fabs()?

651


What is the purpose of ftell?

601


What is "Hungarian Notation"?

639


Want to know how to write a C program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.

1524


Why string is used in c?

586