Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Answer Posted / moinom

#include <iostream>
#include <conio>

void reverse(char a[], int s, int sc );

void reverse(char a[], int s, int sc ){

if ((sc-s)<(s-1))
{
a[sc-s]^=a[s-1];
a[s-1]^=a[sc-s];
a[sc-s]^=a[s-1];
reverse (a, s-1, sc) ;

}

}

void main (){


char a[]="ABCDEFG";

reverse(a, 7, 7);
cout<<a;
getch(); //i just use it to freeze the screen

}

Is This Answer Correct ?    14 Yes 29 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a structure and why it is used?

1291


How can you increase the size of a dynamically allocated array?

1231


What is pointers in c?

1160


why arguments can generally be passed to functions a) sending the values of the arguments b) sending the addresses of the arguments c) a & b d) none of the above

1188


Is there anything like an ifdef for typedefs?

1214


Explain how do you generate random numbers in c?

1128


How is actual parameter different from the formal parameter?

1059


What Is The Difference Between Null And Void Pointer?

1329


Can variables be declared anywhere in c?

1147


What is #define in c?

1106


What are the scope of static variables?

1250


What is difference between array and structure in c?

1261


How can I discover how many arguments a function was actually called with?

1112


a c variable cannot start with a) an alphabet b) a number c) a special symbol d) both b and c above

1283


How do I swap bytes?

1117