How to reverse a string using a recursive function, without
swapping or using an extra memory?
Answer Posted / vishnu
Try this ...
#include <stdio.h>
#include <stdlib.h>
int Rev (char *s, char *b)
{
int i ;
char c ;
if (*s == '\0')
{
return 0 ;
}
c = *s ;
i = Rev (s + 1, b) ;
b[i] = c ;
return i+1 ;
}
int main ()
{
int end ;
char str[] = "Billie jean is not my lover - MJ" ;
end = Rev (str, str) ;
str[end] = '\0' ;
printf ("Now [%s]\n", str) ;
exit (0) ;
}
| Is This Answer Correct ? | 1 Yes | 1 No |
Post New Answer View All Answers
how to write optimum code to divide a 50 digit number with a 25 digit number??
Why do we use header files in c?
What are the advantages of Macro over function?
Explain do array subscripts always start with zero?
which type of aspect you want from the student.
int i[2], j; int *pi;i[0] = 1; i[1] = 5; pi = i; j = *pi + 1 + *(pi + 1)Value of j after execution of the above statements will be a) 7 b) 6 c) 4 d) pointer
Explain what is page thrashing?
What is difference between main and void main?
Can we declare variable anywhere in c?
What header files do I need in order to define the standard library functions I use?
What is mean by data types in c?
If the size of int data type is two bytes, what is the range of signed int data type?
Can you please explain the difference between syntax vs logical error?
What is variables in c?
How do I convert a string to all upper or lower case?