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
How do c compilers work?
What is a dynamic array in c?
What is s or c?
Which are low level languages?
How can I manipulate individual bits?
What are all different types of pointers in c?
How do you initialize pointer variables?
What is the purpose of realloc()?
How do you override a defined macro?
Why & is used in c?
How can I open files mentioned on the command line, and parse option flags?
Can we change the value of constant variable in c?
What functions are in conio h?
What are the features of c languages?
Explain pointer. What are function pointers in C?