CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 69

Thread: Fun C++ Problem

Threaded View

  1. #1
    Join Date
    Sep 2005
    United States

    Fun C++ Problem

    Hey guys!

    This is not a homework assignment or anything.

    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.

    Good luck, this drove me nuts for a while!
    Last edited by dcjr84; October 18th, 2006 at 12:18 AM.
    Please rate my post if you felt it was helpful

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.