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
What are header files and what are its uses in C programming?
How can my program discover the complete pathname to the executable from which it was invoked?
What does dm mean sexually?
What is union in c?
using for loop sum 2 number of any 4 digit number in c language
What are formal parameters?
What are the similarities between c and c++?
Explain the priority queues?
What is dynamic variable in c?
Explain about C function prototype?
How do you define a string?
A float occupies 4 bytes in memory. How many bits are used to store exponent part? since we can have up to 38 number for exponent so 2 ki power 6 6, 6 bits will be used. If 6 bits are used why do not we have up to 64 numbers in exponent?
What math functions are available for integers? For floating point?
Is there anything like an ifdef for typedefs?
#define f(g,h) g##h main O int i=0 int var=100 ; print f ("%d"f(var,10));} wat would be the output??