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
Explain how can I open a file so that other programs can update it at the same time?
What is a structure in c language. how to initialise a structure in c?
What is array of structure in c programming?
What are Macros? What are its advantages and disadvantages?
What is difference between static and global variable in c?
What functions are used in dynamic memory allocation in c?
Explain what does a function declared as pascal do differently?
Input is "rama loves rajesh and rajesh Loves rama also and rajesh wear gloves and bloves" To print output is count the numbers of times repeted the word love without case sensitive.
a formula,a series of steps,or well defined set of rules for solving a problem a) algorithem b) program c) erdiagram d) compiler
What should malloc() do? Return a null pointer or a pointer to 0 bytes?
What are near, far and huge pointers?
What is string function in c?
What is the use of clrscr?
What is the role of && operator in a program code?
What is a char in c?