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 / shivaraj

main()
{
char str[10];
cin>>str;
int len=strlen(str);
reverse(len);
cout<<"Reversed string is: "<<str;
}

void reverse(int len)
{
static int i=0;
str[i]=str[len-1]; //put the char in last pos to first pos
for(j=len-1;j>i;j--)
str[j]=str[j-1]; //shift to right
i++;

if(i==len)
return;

reverse(len);
}

Is This Answer Correct ?    5 Yes 15 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Do you know the difference between exit() and _exit() function in c?

1018


What are the different properties of variable number of arguments?

1106


disply the following menu 1.Disply 2.Copy 3.Append; as per the menu do the file operations 4.Exit

2020


What are near, far and huge pointers?

1015


Is malloc memset faster than calloc?

1018


the number of measuring units from a arbitrary starting point in a record area or control block to some other point a) branching b) recording pointer c) none d) offset

1052


What are the different file extensions involved when programming in C?

1209


List the difference between a While & Do While loops?

1055


Discuss the function of conditional operator, size of operator and comma operator with examples.

1099


#include show(int t,va_list ptr1) { int a,x,i; a=va_arg(ptr1,int) printf(" %d",a) } display(char) { int x; listptr; va_star(otr,s); n=va_arg(ptr,int); show(x,ptr); } main() { display("hello",4,12,13,14,44); }

1245


What are the features of c languages?

1031


what is recursion in C

1023


Explain what is page thrashing?

1056


count = 0; for (i = 1;i < = 10; i++);count = count + i; Value of count after execution of the above statements will be a) 0 b) 11 c) 55 d) array

1041


What is data type long in c?

1029