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
PROGRAM TO WRITE CONTENTS OF 1 FILE IN REVERSE TO ANOTHER FILE,PROGRAM TO COPY 1 FILE TO ANOTHER BY SPECIFYING FILE NAMES AS COMMAND LINE
What does it mean when a pointer is used in an if statement?
Is c procedural or functional?
How is actual parameter different from the formal parameter?
What does the message "automatic aggregate intialization is an ansi feature" mean?
Explain what are compound statements?
What is pointer in c?
What is the purpose of scanf() and printf() functions?
Explain is it valid to address one element beyond the end of an array?
What is a global variable in c?
Array is an lvalue or not?
What is the ANSI C Standard?
Hai what is the different types of versions and their differences
What are the restrictions of a modulus operator?
Explain what is the difference between text files and binary files?