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
What is derived datatype in c?
When should I declare a function?
What is class and object in c?
What does 3 mean in texting?
Explain built-in function?
Hai sir, I had planned to write the NIC scientific engineer exam , plz post the sample question......
write a program to convert a expression in polish notation(postfix) to inline(normal) something like make 723+* (2+3) x 7 (not sure) just check out its mainly printing expression in postfix form to infix.
Is it possible to have a function as a parameter in another function?
Explain how to reverse singly link list.
Is it better to use a macro or a function?
What is null pointer in c?
int i=3; this declaration tells the C compiler to a) reserve space in memory to hold the integer value b) associate the name i with this memory location c) store the value 3 at this location d) all the above
What is wrong in this statement?
Explain what is the advantage of a random access file?
What does stand for?