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
List the difference between a 'copy constructor' and a 'assignment operator' in C?
write a program fibonacci series and palindrome program in c
What is meant by initialization and how we initialize a variable?
How to delete a node from linked list w/o using collectons?
What is a pointer and how it is initialized?
Write a program to reverse a string.
Explain indirection?
What is main return c?
Write the control statements in C language
Explain what header files do I need in order to define the standard library functions I use?
What is the difference between functions abs() and fabs()?
What is the purpose of ftell?
What is "Hungarian Notation"?
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.
Why string is used in c?