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
Do you know the difference between exit() and _exit() function in c?
What are the different properties of variable number of arguments?
disply the following menu 1.Disply 2.Copy 3.Append; as per the menu do the file operations 4.Exit
What are near, far and huge pointers?
Is malloc memset faster than calloc?
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
What are the different file extensions involved when programming in C?
List the difference between a While & Do While loops?
Discuss the function of conditional operator, size of operator and comma operator with examples.
#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); }
What are the features of c languages?
what is recursion in C
Explain what is page thrashing?
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
What is data type long in c?