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
Explain what does a function declared as pascal do differently?
hai iam working in sap sd module for one year and working in lumax ind ltd in desp department but my problem is i have done m.b.a in hr/marketing and working sap sd there is any combination it. can you give right solution of my problem. and what can i do?
What is difference between Structure and Unions?
What are the different types of objects used in c?
How can you increase the size of a statically allocated array?
Explain how can I write functions that take a variable number of arguments?
What is storage class?
What is the modulus operator?
What is binary tree in c?
Are the variables argc and argv are always local to main?
What is a list in c?
What is size of union in c?
How do you convert strings to numbers in C?
What is the purpose of realloc()?
How do you construct an increment statement or decrement statement in C?