write a C code
to reverse a string using a recursive function, without
swapping or using an extra memory.
Answers were Sorted based on User's Feedback
Answer / valli
void reverse(char s[],int len)
{
putchar(s[len]);
len--;
if(len>=0)
reverse(s,len);
return;
}
Is This Answer Correct ? | 49 Yes | 33 No |
Answer / noone
/* this one is a copy of a earlier one posted i just made a
small adjustment */
void reverse(char *str)
{
if(*str)
{
reverse(str+1);
putchar(*str);
}
}
Is This Answer Correct ? | 18 Yes | 5 No |
Answer / sampath
void reverse(*str)
{
if(*str)
{
reverse(str+1);
putchar(*str);
}
}
Is This Answer Correct ? | 58 Yes | 51 No |
Answer / asdf
void reverse(*str)
{
if(*str){
reverse(++str);
str--;
printf("%c",*str);
}
}
Is This Answer Correct ? | 16 Yes | 9 No |
Answer / mohan
#include <stdio.h>
#include <string.h>
void reverse(char **s, int start, int last)
{
char tmp;
if (start >= last)
return;
char *s2 = *s;
tmp = s2[start];
s2[start] = s2[last];
s2[last] = tmp;
reverse(s, start + 1, last - 1);
}
int main()
{
char *s = strdup("Hello World");
printf("%s\n", s);
reverse(&s, 0, strlen(s) - 1);
printf("%s\n", s);
}
Is This Answer Correct ? | 5 Yes | 1 No |
Answer / billy
string reverse with out recursion
void rev( char *p )
{
char tmp;
int len =strlen(p)-1;
for( int i=0 ; i <= len/2 ; i++ )
{
tmp = p[i] ;
p[i] = p[len - i ] ;
p[len - i ] = tmp ;
}
printf("%s",p);
}
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / jainendra
#include<stdio.h>
#define MAX 100
char* getReverse(char[]);
int main(){
char str[MAX],*rev;
printf("Enter any string: ");
scanf("%s",str);
rev = getReverse(str);
printf("Reversed string is: %s",rev);
return 0;
}
char* getReverse(char str[]){
static int i=0;
static char rev[MAX];
if(*str){
getReverse(str+1);
rev[i++] = *str;
}
return rev;
}
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / sanny
#include<stdio.h>
#include<conio.h>
main()
{
int num, rem=0;
printf("\n Enter the number ");
scanf("%d", &num);
while(num>0)
{
rem = (rem * 10) + (num % 10);
num = num / 10;
}
printf("\n Reverse of the number is %d", rem);
getch();
}
Is This Answer Correct ? | 10 Yes | 15 No |
Answer / piyush kumar
char gacstring="piyush";
int giindex=0;
voidfnreverse();
void main()
while(gacstring[giindex]!='\0'){
giindex++;
voidfnreverse();
}
if(giindex>0)
giindex--;
printf("%c",chargacstring);
return 0;
}
Is This Answer Correct ? | 4 Yes | 14 No |
array of pointer pointer to array pointer to pointer
What is a wrapper function in c?
Hai sir, I had planned to write the NIC scientific engineer exam , plz post the sample question......
What is wild pointer in c?
34.what are bitwise shift operators? 35.what are bit fields? What is the use of bit fields in a structure declaration? 36.what is the size of an integer variable? 37.what are the files which are automatically opened when a c file is executed? 38.what is the little endian and big endian? 39.what is the use of fflush() function? 40.what is the difference between exit() and _exit() functions? 41.where does malloc() function get the memory? 42.what is the difference between malloc() and calloc() function? 43.what is the difference between postfix and prefix unary increment operators?
write a program without using main function?
what is memory leak?
What are the advantages and disadvantages of c language?
When was c language developed?
write a program to display & create a rational number
Function which gives a pointer to a binary trees const an integer value at each code, return function of all the nodes in binary tree.?
What is wrong with this program statement? void = 10;