Programming Puzzle

Joined
Mar 9, 2004
Messages
3,322
Saw this earlier today figured it was semi interesting so I'm passing it on here.

Code:
int i, n = 20;

for (i=0; i<n; i--) 
{ 
	cout << "x" << endl; 
}

Make that code print out the character 'x' twenty times by only replacing one character in three different ways. (You cant insert a character and must replace an existing character)

Tip: You are only going to be changing the for loops test section. -- lol, my tips wrong for one of the more obvious ones. =P

Enjoy!
 
I'm assuming that this is written in C and I don't know C but I'll rewrite them in java

Code:
int i, n = 20;

for(i = 0; i < n; n--);
{
       System.out.println("x");
}

All I did was replaced the i-- into the n--
 
Back
Top