|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
int i=0;
char word[50]; printf("enter the word"); scanf("%s",word); reserve(word,i); void reserve(char word[], int i) { if(word[i]!='\0') { reserve(&word[i+1],i+1); printf("%c",word[i+1]); } } |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
emre esirik(hacettepe computer science and engineering) wrote:
> int i=0; > char word[50]; > printf("enter the word"); > scanf("%s",word); > reserve(word,i); > > void reserve(char word[], int i) > { > if(word[i]!='\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 ... -- Eric Sosman esosman@ieee-dot-org.invalid |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
In article <9dKdnZaZCfod0dranZ2dnUVZ_gSdnZ2d@comcast.com>,
Eric Sosman <esosman@ieee-dot-org.invalid> wrote: > 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 -- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Fri, 23 Nov 2007 11:53:31 -0800 (PST), "emre esirik(hacettepe
computer science and engineering)" <emreesirik@gmail.com> wrote: 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 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
"emre esirik(hacettepe computer science and engineering)"
<emreesirik@gmail.com> a écrit dans le message de news: 17651794-5cfe-490a-9780-0107dee5e579...oglegroups.com... > int i=0; > char word[50]; > printf("enter the word"); > scanf("%s",word); > reserve(word,i); > > void reserve(char word[], int i) > { > if(word[i]!='\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. -- Chqrlie. |
|
![]() |
| Outils de la discussion | |
|
|