The puzzle is taken from Tanya Khovanova's web page (she has a nice blog too, probably the only one I visit on a semiregular basis):
The puzzle is to find 3 ways to make this C program print 20 dashes by changing or adding exactly one character.
Finding one way is easy, two isn't that hard either, but for the third way I had to look up some (for me) obscure syntax stuff on the internet.
More variations are to make it print 21 characters, and to print 1 character (this one is cute).
Perhaps people could put spoilers if they write solutions here...
Code:
int i, n = 20;
for (i = 0; i < n; i--)
{
printf("-");
}
The puzzle is to find 3 ways to make this C program print 20 dashes by changing or adding exactly one character.
Finding one way is easy, two isn't that hard either, but for the third way I had to look up some (for me) obscure syntax stuff on the internet.
More variations are to make it print 21 characters, and to print 1 character (this one is cute).
Perhaps people could put spoilers if they write solutions here...