1. OOT: Interesting C quiz
- Posted by akusaya at gmx.net Feb 16, 2004
- 473 views
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!
2. Re: OOT: Interesting C quiz
- Posted by Guillermo Bonvehi <knixeur at speedy.com.ar> Feb 17, 2004
- 471 views
It says it can display 21 - signs too, what about n = 21;? :P aku saya wrote: > > >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...?? > >
3. Re: OOT: Interesting C quiz
- Posted by akusaya at gmx.net Feb 17, 2004
- 481 views
It says you can only change one character... either one of the below solutions or changing n=20 to n=21.. But if you change n=20 to n=21 the result will be infinity loop.. ^^ G> It says it can display 21 - signs too, what about n = 21;? :P G> aku saya wrote: >> >> >>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...??