How to reverse a string using a recursive function, without
swapping or using an extra memory?
Answer Posted / asif
#include <stdio.h>
#include <string.h>
void reverse(char *str)
{
if (*str == '\0')
return;
reverse(str+1);
printf("%c", *str);
}
int main()
{
char str[50];
char *ptr;
printf("Enter the string: ");
//scanf("%s", str);
fgets(str,50,stdin);
ptr = strchr(str,'\n');
*ptr = '\0';
printf("Reversed string: ");
reverse(str);
printf("\n");
return 1;
}
| Is This Answer Correct ? | 2 Yes | 3 No |
Post New Answer View All Answers
What is ponter?
#include
Explain about C function prototype?
Devise a program that inputs a 3 digit number n and finds out whether the number is prime or not. Find out its factors.
Is it better to bitshift a value than to multiply by 2?
Explain how do you list a file’s date and time?
Explain how do you determine a file’s attributes?
Which one to choose from 'initialization lists' or 'assignment', for the use in the constructor?
What is a union?
to find the closest pair
what is bit rate & baud rate? plz give wave forms
A c program to display count values from 0 to 100 and flash each digit for a secong.reset the counter after it reaches 100.use for loop,. pls guys hepl me.. :(
How do we print only part of a string in c?
Difference between Shallow copy and Deep copy?
What is the c value paradox and how is it explained?