2014-09-25

Change 1 character puzzle #1

Add or replace at most 1 character in the longest line of the following program so that it will print 20 dots. There are at least 3 solutions.

#include <stdio.h>
int main() {
  int i, n = 20; for (i = 0; i < n; i--) putchar('.');
  return 0;
}

SPOILER ALERT! Here are 3 solutions:

int i, n = 20; for (i = 0; -i < n; i--) putchar('.');
int i, n = 20; for (i = 0; i < n; n--) putchar('.');
int i, n = 20; for (i = 0; i + n; i--) putchar('.');

No comments: