how can I puts a char array reserve by recursion algoritym?

  • Thread starter emre esirik(hacettepe computer science and enginee
  • Start date
E

emre esirik(hacettepe computer science and enginee

int i=0;
char word[50];
printf("enter the word");
scanf("%s",word);
reserve(word,i);

void reserve(char word[], int i)
{
if(word!='\0')
{
reserve(&word[i+1],i+1);
printf("%c",word[i+1]);
}
}
 
E

Eric Sosman

emre said:
int i=0;
char word[50];
printf("enter the word");
scanf("%s",word);
reserve(word,i);

void reserve(char word[], int i)
{
if(word!='\0')
{
reserve(&word[i+1],i+1);
printf("%c",word[i+1]);
}
}


Solution #1: Suppose the word is just one letter long,
or is the zero-letter word "". Can you think of a way to
reverse it? Good! Now suppose you know how to reverse words
of N letters. Can you use that method along with a few other
simple operations to reverse a word of N+2 letters? (Hint:
write N+2 as 1+N+1.)

Solution #2: If you always use words like EWE or NOON
or MADAM or DENNED or DEIFIED or REDIVIDER, the program will
be fairly simple.

Remark: I cannot imagine why anyone would want to use
recursion for this problem, but ...
 
W

Walter Roberson

Eric Sosman said:
Solution #2: If you always use words like EWE or NOON
or MADAM or DENNED or DEIFIED or REDIVIDER, the program will
be fairly simple.
Remark: I cannot imagine why anyone would want to use
recursion for this problem, but ...

We've seen it before several times, as a homework problem.

..melborp krowemoh a sa ,semit lareves erofeb ti nees ev'eW
 
B

Barry Schwarz

On Fri, 23 Nov 2007 11:53:31 -0800 (PST), "emre esirik(hacettepe

Your question was answered in response to your post in
alt.comp.lang.learn.c-c++. Please don't post separate questions in
different newsgroups. If you must post to multiple groups, post a
single message to all the groups by using multiple addresses.


Remove del for email
 
C

Charlie Gordon

"emre esirik(hacettepe computer science and engineering)"
int i=0;
char word[50];
printf("enter the word");
scanf("%s",word);
reserve(word,i);

void reserve(char word[], int i)
{
if(word!='\0')
{
reserve(&word[i+1],i+1);
printf("%c",word[i+1]);
}
}


Try harder! You are off by one on about every line ;-)
I have reversations with your choice of algorithm.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,433
Messages
2,571,683
Members
48,796
Latest member
Greg L.

Latest Threads

Top