RE: Re[2]: OOT: Interesting C quiz
- Posted by Philip Deets <philip1987 at hotmail.com> Feb 17, 2004
- 518 views
Show them please, I'm curious. Phil 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! > >> > >>