How to reverse a string using a recursive function, without
swapping or using an extra memory?
Answer Posted / prakash
Another version that actually reverses the string...
#include <stdio.h>
char *reverse(char *sstr, char *str, char c)
{
if (*str == '\0')
return sstr;
sstr = reverse(sstr, str+1, *(str+1));
*sstr = c;
return (sstr+1);
}
int main()
{
char str[100];
printf("Enter the string: ");
scanf("%s", str);
reverse(str, str, *(str + 0));
printf("Reversed string: %s\n", str);
return 1;
}
Is This Answer Correct ? | 25 Yes | 11 No |
Post New Answer View All Answers
What is selection sort in c?
What is adt in c programming?
Given below are three different ways to print the character for ASCII code 88. Which is the correct way1) char c = 88; cout << c << " ";2) cout.put(88);3) cout << char(88) << " "; a) 1 b) 2 c) 3 d) constant
write a c program to calculate sum of digits till it reduces to a single digit using recursion
If a five digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits.For example if the number that is input is 12391 then the output should be displayed as 23402
how do you execute a c program in unix.
Write a program to display all the prime nos from 1 to 1000000, your code should not take time more than a minute to display all the nos.
What is meant by preprocessor in c?
What is a null pointer in c?
What should malloc(0) do?
In c language can we compile a program without main() function?
What is the auto keyword good for?
What is a global variable in c?
What are the disadvantages of external storage class?
‘SAVEPOINT’ and ‘ROLLBACK’ is used in oracle database to secure the data comment. Give suitable examples of each with sql command.