How to reverse a string using a recursive function, without
swapping or using an extra memory?
Answer Posted / prakash
#include <stdio.h>
void reverse(char *str)
{
if (*str == '\0')
return;
reverse(str+1);
printf("%c", *str);
}
int main()
{
char str[50];
printf("Enter the string: ");
scanf("%s", str);
printf("Reversed string: ");
reverse(str);
printf("\n");
return 1;
}
| Is This Answer Correct ? | 23 Yes | 24 No |
Post New Answer View All Answers
What is c language in simple words?
How can I do peek and poke in c?
Explain how do you convert strings to numbers in c?
What are the differences between Structures and Arrays?
What is c value paradox explain?
Define the scope of static variables.
When I set a float variable to, say, 3.1, why is printf printing it as 3.0999999?
How do I copy files?
Explain what could possibly be the problem if a valid function name such as tolower() is being reported by the c compiler as undefined?
What is keyword in c?
what will be the output for the following main() { printf("hi" "hello"); }
In c programming typeing to occupy the variables in memory space. if not useing the variable the memory space is wasted.ok, how to avoid the situation..? (the variable is used & notused)
How can I remove the leading spaces from a string?
How can I find out the size of a file, prior to reading it in?
Write a program to use switch statement.