If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Fun C++ Problem

A buddy of mine who works for a software company in Michigan sent me this problem.

He said it was on their yearly technical tests that they give programmers.

I only could figure out two ways to do this... and that took me a LONG time.

As far as the third solution goes, I have no idea, and neither does my friend. I can give you the first two though later on.

take the following code:

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

by changing only ONE character in the above code, meaning you cannot change 20 to 31, because you will have changed two characters, you can change 20 to 21, because you only changed the 0, do the following:

find 3 ways to make the above code print x 20 times (by changing only one character).

And, according to my friend, he said his boss has been giving this problem yearly since about 1999, and no one has figured out all three ways to do it.

Re: Fun C++ Problem

This is one of the trick questions a friend of mine was asked in the interview for his job at our current companies. I remember that I needed 2 minutes to find the first two, and more than 10 minutes to find the 3rd. It's a good one!