RE: OOT: Interesting C quiz

new topic     » topic index » view thread      » older message » newer message

I think listfilter mangled the code...


It should be:

/*
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= 20; /*= 20 was changed to a space!*/
  for(i=0; i<n; i--) printf("-");
  return 0;
}

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!
> 
>

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu