Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] C puzzle



>>>>> "TM" == Tod McQuillin <devin@example.com> writes:

    TM> This C program:

    TM> main() {
    TM>   int i, n=20;
    TM>   for(i = 0 ; i < n ; i--)
    TM>     printf("-");
    TM> }

    TM> Can be modified into a correct program for printing 20 '-'
    TM> characters in a row by replacing a single character of the
    TM> code.

    TM> In fact, there are three different ways to do it.

All replacements are on line 3:

1) 'i' -> 'n'

main() {
  int i, n=20;
  for(i = 0 ; i < n ; n--)
    printf("-");
}

2) ' ' -> '-'

main() {
  int i, n=20;
  for(i = 0 ;-i < n ; i--)
    printf("-");
}

3) '<' -> '+'

main() {
  int i, n=20;
  for(i = 0 ; i + n ; i--)
    printf("-");
}

cheers
Viktor


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links