How to reverse a string using a recursive function, without
swapping or using an extra memory?
Answer Posted / boomer
void Rstring( char *str,int len)
{
for(int i = 0; i < (len/2); i++)
{
str[i] ^= str[len-i-1];
str[len-i-1] ^= str[i];
str[i] ^= str[len-i-1];
}
}
int main( void )
{
char str[] = "my string";
printf("Actual string is [%s]\n", str);
Rstring(str,strlen(str));
printf("Reversed string is [%s]\n", str);
}
I dont call this swaping, coz it's not, recursive creates
new incarnations of the reverse func, EXTRA MEMORY BIG
TIME!!!
| Is This Answer Correct ? | 21 Yes | 40 No |
Post New Answer View All Answers
Explain what are binary trees?
Are pointers really faster than arrays?
1) write a program to generate 1st n fibonacci prime numbers using Nested if 2) write a program to generate twin prime numbers from m to n using nested if 3) write a program to check whether a given integer is a strong number or not using nested if 4) Write a program to generate prime factors of a given integer using nested if 5)write a program to generate prime numbers from m to n using nested if 6)write a program to generate perfect numbers from m to n using nested if 7)write a program to generate the pallindromes from m to n using neste if 8)write a program to generate armstrong numbers from m to n using nested if 9)write a program to generate strong numbers from m to n using nested if
How can my program discover the complete pathname to the executable from which it was invoked?
How do you define CONSTANT in C?
What is variable initialization and why is it important?
What is getch?
When should structures be passed by values or by references?
Do you have any idea how to compare array with pointer in c?
A program is required to print your biographic information including: Names, gender, student Number, Cell Number, line of study and your residential address.
What are the 5 types of organizational structures?
Describe newline escape sequence with a sample program?
What is the advantage of using #define to declare a constant?
What is preprocessor with example?
How can variables be characterized?