How to reverse a string using a recursive function, with
swapping?
Answer Posted / kamrul islam
#include<stdio.h>
#include<string.h>
char s1[50];
void reverse();
int main()
{
scanf("%s",s1);
reverse();
return 0;
}
void reverse()
{
char temp;
int n=strlen(s1);
static int i=0;
if (i<n/2)
{
temp=s1[n-i-1];
s1[n-i-1]=s1[i];
s1[i]=temp;
i++;
reverse();
}
else
printf("The reverse string is %s\n",s1);
}
~
| Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
How can I get random integers in a certain range?
Explain what is wrong with this program statement?
What is a double c?
What are lookup tables in c?
Do you know the difference between exit() and _exit() function in c?
what is a constant pointer in C
what value is returned to operating system after program execution?
Does * p ++ increment p or what it points to?
What is use of bit field?
What is printf () in c?
What is the right way to use errno?
write a c program in such a way that if we enter the today date the output should be next day's date.
How can I read data from data files with particular formats?
write a C program: To recognize date of any format even formats like "feb-02-2003","02-february-2003",mm/dd/yy, dd/mm/yy and display it as mm/dd/yy.
What is dynamic memory allocation?