How to reverse a string using a recursive function, without
swapping or using an extra memory?

Answer Posted / cmp

#include <stdio.h>
void print(char *s,int size){
if(size<0)
printf(" ");
else

{
printf("%c",*(s+size-1));
print(s,size-1);
}
}

void main(){
char *s={"aliveli"};
int size=0,i=0;

while(*(s+i)!='\0'){
size++;
i++;
}
print(s,size);
}

Is This Answer Correct ?    6 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is operator promotion?

629


What is string concatenation in c?

568


Is c a great language, or what?

604


a program that can input number of records and can view it again the record

1484


Draw a diagram showing how the operating system relates to users, application programs, and the computer hardware ?

2120






Can include files be nested? How many levels deep can include files be nested?

660


Do you know the purpose of 'register' keyword?

642


define string ?

669


What is floating point constants?

692


Explain zero based addressing.

608


How to write c functions that modify head pointer of a linked list?

545


What is the purpose of sprintf?

621


How many parameters should a function have?

668


What are the salient features of c languages?

625


Why cant I open a file by its explicit path?

593