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


Please Help Members By Posting Answers For Below Questions

Explain how can I open a file so that other programs can update it at the same time?

863


What is a structure in c language. how to initialise a structure in c?

830


What is array of structure in c programming?

1006


What are Macros? What are its advantages and disadvantages?

860


What is difference between static and global variable in c?

760


What functions are used in dynamic memory allocation in c?

785


Explain what does a function declared as pascal do differently?

915


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.

1848


a formula,a series of steps,or well defined set of rules for solving a problem a) algorithem b) program c) erdiagram d) compiler

850


What should malloc() do? Return a null pointer or a pointer to 0 bytes?

815


What are near, far and huge pointers?

838


What is string function in c?

740


What is the use of clrscr?

788


What is the role of && operator in a program code?

794


What is a char in c?

760