Re[4]: OOT: Interesting C quiz
- Posted by akusaya at gmx.net Feb 17, 2004
- 579 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!