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
How can you call a function, given its name as a string?
Difference between linking and loading?
Why we write conio h in c?
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?
Can we declare a function inside a function in c?
What should malloc(0) do?
What is meant by gets in c?
What are shell structures used for?
What is pointer to pointer in c with example?
what is the diffrenet bettwen HTTP and internet protocol
What are the string functions? List some string functions available in c.
In this problem you are to write a program that will cut some number of prime numbers from the list of prime numbers between 1 and N.Your program will read in a number N; determine the list of prime numbers between 1 and N; and print the C*2 prime numbers from the center of the list if there are an even number of prime numbers or (C*2)-1 prime numbers from the center of the list if there are an odd number of prime numbers in the list.
Why is c still so popular?
What is use of null pointer in c?
What is hashing in c?