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 the use of #pragma exit?
When is the “void” keyword used in a function?
Write a program to print factorial of given number without using recursion?
What is a substring in c?
What is static function in c?
In which language linux is written?
Is return a keyword in c?
If i have an array 0 to 99 i.e,(Size 100) I place the values 1 to 100 randomly like a[0]=29,a[1]=56 upto array[99].. the values are only between 1 to 100. getting the array values by using scanf.. If i entered one wrong element value line a[56]=108. how can i find it.. and also how to find the missing value in 1 to 100.. and i want to replace the missing values.. any one of them know please post your answer..
write a c program to do the following: a) To find the area of a triangle. b) To convert the temperature from Fahrenheit to Celsius. c) To convert the time in hours : minutes : seconds to seconds.
I need a sort of an approximate strcmp routine?
a formula,a series of steps,or well defined set of rules for solving a problem a) algorithem b) program c) erdiagram d) compiler
What is the deal on sprintf_s return value?
Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal. [ I gave the obvious solution of taking % 10 and / 10, which gives us the decimal value in reverse order. This requires an array since we need to print it out in the correct order. The interviewer wasn't too pleased and asked me to give a solution which didn't need the array ].
Explain 'bus error'?
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.