How to reverse a string using a recursive function, with
swapping?
Answer Posted / vignesh1988i
#include<stdio.h>
#include<conio.h>
char a1[50]; //GLOABAL VAR.
void reverse(int);
void main()
{
int count=0;
printf("enter the string :");
scanf("%s",a1);
for(int i=0;a1[i]!='\0';i++)
count++;
reverse(count);
getch();
}
void reverse(int count1)
{
char temp;
static int i=0;
if(i<=count1/2)
{
temp=a1[i];
a1[i]=a1[count1-1];
a1[count1-1]=temp;
i++;
reverse(--count1);
}
else
printf("\nthe reversed string is :%s",a1);
}
thank u
| Is This Answer Correct ? | 8 Yes | 1 No |
Post New Answer View All Answers
Discuss the function of conditional operator, size of operator and comma operator with examples.
What are the key features in c programming language?
Explain how are 16- and 32-bit numbers stored?
What is difference between union and structure in c?
How can I read a binary data file properly?
How would you rename a function in C?
When should the const modifier be used?
If a variable is a pointer to a structure, then which operator is used to access data members of the structure through the pointer variable?
What is the value of a[3] if integer a[] = {5,4,3,2,1}?
How is actual parameter different from the formal parameter?
How can I find out if there are characters available for reading?
typedef struct{ char *; nodeptr next; } * nodeptr ; What does nodeptr stand for?
What is void main ()?
What is %lu in c?
Find the second largest element in an array with minimum no of comparisons and give the minimum no of comparisons needed on an array of size N to do the same.