1. Re[4]: OOT: Interesting C quiz
- Posted by akusaya at gmx.net Feb 17, 2004
- 580 views
OK, 1. change i-- to n-- 2. change i<n to -i<n 3. change i<n to i+n (tricky!) 4. change i<n to ~i<n The question says there are at least 4 ways,, who knows there are more...?? P> Show them please, I'm curious. P> Phil P> akusaya at gmx.net wrote: >> >> >> Yes i think... >> >> btw after several thinking and asking friends I managed to get all >> solutions! Thanks! >> >> C> I think listfilter mangled the code... >> >> >> C> It should be: >> >> C> /* >> C> Find at least 4 different ways to change only one >> C> character in the C code below so it will print the >> C> minus sign "-" 20 or 21 times only. >> C> */ >> >> C> #include <stdio.h> >> >> C> main() >> C> { >> C> int i, n= 20; /*= 20 was changed to a space!*/ >> C> for(i=0; i<n; i--) printf("-"); >> C> return 0; >> C> } >> >> C> akusaya at gmx.net wrote: >> >> >> >> >> >> Got it from http://www.genesim.co.il/cprog.htm >> >> >> >> For C programmers, here is a C code quiz. You are invited to give it a >> >> try. >> >> >> >> /* >> >> Find at least 4 different ways to change only one >> >> character in the C code below so it will print the >> >> minus sign "-" 20 or 21 times only. >> >> */ >> >> >> >> #include <stdio.h> >> >> >> >> main() >> >> { >> >> int i, n ; >> >> for(i=0; i<n; i--) printf("-"); >> >> return 0; >> >> } >> >> >> >> =========================== >> >> I can only know 2 of them, >> >> 1. change i-- to n-- >> >> 2. change i<n to -i<n >> >> >> >> Can anyone help me finding the other two? I am very curious... >> >> >> >> Thx! >> >> >> >> P> TOPICA - Start your own email discussion group. FREE!
2. Re: Re[4]: OOT: Interesting C quiz
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Feb 18, 2004
- 578 views
On Tue, 17 Feb 2004 21:53:42 +0800, aku saya <akusaya at gmx.net> wrote: >1. change i-- to n-- >2. change i<n to -i<n >3. change i<n to i+n (tricky!) >4. change i<n to ~i<n > >The question says there are at least 4 ways,, who knows there are >more...?? Does i^n work?
3. Re: Re[4]: OOT: Interesting C quiz
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Feb 18, 2004
- 555 views
On Wed, 18 Feb 2004 10:38:04 +0000, Pete Lomax <petelomax at blueyonder.co.uk> wrote: > > >On Tue, 17 Feb 2004 21:53:42 +0800, aku saya <akusaya at gmx.net> wrote: > >>1. change i-- to n-- >>2. change i<n to -i<n >>3. change i<n to i+n (tricky!) >>4. change i<n to ~i<n >> >>The question says there are at least 4 ways,, who knows there are >>more...?? >Does i^n work? Sorry, I just realised that's another infinite loop, never mind. Pete