How to reverse a string using a recursive function, with
swapping?
Answer Posted / vignesh1988i
the corrected code is:::
#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!=count)
{
temp=a1[i];
a1[i]=a1[count1-1];
a1[count1-1]=temp;
i++;
reverse(--count1);
}
else
printf("\nthe reversed string is :%s",a1);
}
| Is This Answer Correct ? | 1 Yes | 3 No |
Post New Answer View All Answers
What is difference between far and near pointers?
What is the use of a static variable in c?
What are different storage class specifiers in c?
Is fortran faster than c?
Explain can you assign a different address to an array tag?
Is there anything like an ifdef for typedefs?
What does nil mean in c?
WHICH TYPE OF JOBS WE GET BY WRITING GROUPS .WHEN THE EXAMS CONDUCTED IS THIS EXAMS ARE CONDUCTED EVERY YEAR OR NOT.PLS TELL ME THE ANSWER
Why does this code crash?
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 getch () for?
How do I read the arrow keys? What about function keys?
Can i use “int” data type to store the value 32768? Why?
What header files do I need in order to define the standard library functions I use?
What's the total generic pointer type?