How to reverse a string using a recursive function, without
swapping or using an extra memory?
Answer Posted / moinom
#include <iostream>
#include <conio>
void reverse(char a[], int s, int sc );
void reverse(char a[], int s, int sc ){
if ((sc-s)<(s-1))
{
a[sc-s]^=a[s-1];
a[s-1]^=a[sc-s];
a[sc-s]^=a[s-1];
reverse (a, s-1, sc) ;
}
}
void main (){
char a[]="ABCDEFG";
reverse(a, 7, 7);
cout<<a;
getch(); //i just use it to freeze the screen
}
Is This Answer Correct ? | 14 Yes | 29 No |
Post New Answer View All Answers
hi friends how r u as soon in satyam my interview is start but i m very confusued ta wat i do plz help me frndz wat can i do plz tell me some question and answers related with "C" which r asked in the interview .
what is a constant pointer in C
What is putchar() function?
What are the features of c languages?
How can I handle floating-point exceptions gracefully?
What are global variables and explain how do you declare them?
Is it possible to execute code even after the program exits the main() function?
what is ur strangth & weekness
What happens if a header file is included twice?
What is the difference between scanf and fscanf?
Can a local variable be volatile in c?
What is wrong with this initialization?
What is the newline escape sequence?
A SIMPLE PROGRAM OF GRAPHICS AND THEIR OUTPUT I WANT SEE WAHAT OUTOUT OF GRAPHICS PROGRAM
What are the key features in c programming language?