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
What is a union?
What is c language and why we use it?
Differentiate between null and void pointers.
write an algorithm to display a square matrix.
What is the behavioral difference when include header file in double quotes (“”) and angular braces (<>)?
Why are algorithms important in c program?
Write a program to maintain student’s record. Record should
not be available to any unauthorized user. There are three
(3) categories of users. Each user has its own type. It
depends upon user’s type that which kind of operations user
can perform. Their types and options are mentioned below:
1. Admin
(Search Record [by Reg. No or Name], View All Records,
Insert New Record, Modify Existing Record)
2. Super Admin
(Search Record [by Reg. No or Name], View All Records,
Insert New Record, Modify Existing Record, Delete Single Record)
3. Guest
(Search Record [by Reg. No or Name], View All Records)
When first time program runs, it asks to create accounts.
Each user type has only 1 account (which means that there
can be maximum 3 accounts). In account creation, following
options are required:
Login Name: <6-10 alphabets long, should be unique>
Password: <6-10 alphabets long, should not display
characters when user type>
Confirm Password:
Do you have any idea about the use of "auto" keyword?
Why pointers are used?
How can I get back to the interactive keyboard if stdin is redirected?
Is it fine to write void main () or main () in c?
What is a good data structure to use for storing lines of text?
What is difference between function overloading and operator overloading?
Lists the benefits of c programming language?
What is the difference between c and python?