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 c++ used for today?
What is 1d array in c?
How can I automatically locate a programs configuration files in the same directory as the executable?
Can we assign integer value to char in c?
What is memcpy() function?
How can I find the modification date and time of a file?
What are qualifiers and modifiers c?
Can we add pointers together?
What is the difference between int main and void main?
Why pointers are used?
Write a code to generate divisors of an integer?
Suppose we have a table name EMP as below. We want to perform a operation in which, I want to change name ‘SMITH’ from as ‘SMITH JAIN’. Also I want to change the name of the column from ENAME to E_NAME. EMPNO ENAME JOB MGR HIREDATE SAL 7369 SMITH Coder 7902 17-DEC-80 800 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 7521 WARD SALESMAN 7698 22-FEB-81 1250
How to draw the flowchart for structure programs?
How will you declare an array of three function pointers where each function receives two ints and returns a float?
What is structure in c definition?