How to reverse a string using a recursive function, with
swapping?
Answer Posted / vignesh1988i
my next logic:::
#include<stdio.h>
#include<conio.h>
void reverse(char*,char*);
void main()
{
char a1[50],*p;
int count=0;
printf("enter the string:");
scanf("%s",a1);
for(int i=0;a[i]!='\0';i++)
count++;
p=a1+(count-1);
reverse(a1,p);
printf("the reversed one is : %s",a1);
getch();
}
void reverse(char *a1,char *p)
{
char temp;
if(a1<=p)
{
temp=*a1;
*a1=*p;
*p=temp;
reverse(++a1,--p);
}
}
thank u
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
Why is %d used in c?
Can the curly brackets { } be used to enclose a single line of code?
the number of measuring units from a arbitrary starting point in a record area or control block to some other point a) branching b) recording pointer c) none d) offset
What is action and transformation in spark?
How can I find the modification date and time of a file?
if p is a string contained in a string?
Difference between MAC vs. IP Addressing
Is file a keyword in c?
What is the difference between char array and char pointer?
What is difference between function overloading and operator overloading?
How do we open a binary file in Read/Write mode in C?
What is binary tree in c?
The number of measuring units from an arbitarary starting point in a record,area,or control block to some other point a) recording pointer b) offset c) branching d) none
What are the output(s) for the following ? #include char *f() {char *s=malloc(8); strcpy(s,"goodbye")} main() { char *f(); printf("%c",*f()='A'); }
Do pointers take up memory?