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 volatile variable how do you declare it?
What is a void pointer in c?
What are local variables c?
What is omp_num_threads?
How can you restore a redirected standard stream?
What is the use of parallelize in spark?
How can I call a function with an argument list built up at run time?
What is difference between main and void main?
What is an arrays?
Can I use base-2 constants (something like 0b101010)? Is there a printf format for binary?
What is break statement?
What is function prototype in c language?
Why is it usually a bad idea to use gets()? Suggest a workaround.
What are global variables and explain how do you declare them?
cin.ignore(80, _ _);This statement a) ignores all input b) ignores the first 80 characters in the input c) ignores all input till end-of-line d) iteration