Fun C++ Problem - Page 5
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 5 of 5 FirstFirst ... 2345
Results 61 to 69 of 69

Thread: Fun C++ Problem

  1. #61
    Join Date
    Nov 2011
    Posts
    2

    Re: Fun C++ Problem

    Quote Originally Posted by VladimirF View Post
    If n is -20, i=0 will never be less than n.
    Interestingly, since I didnít want to read past the first few posts, I did not realize that I played this game five years ago, and accidentally found (again) all three solutions. Again without timing; about 10 minutes, I guess.
    Do I get a double bonus?
    i is DEcremented, not INcremented. So i will= -1, -2, -3...etc until it passes -20.

  2. #62
    Join Date
    Aug 2009
    Posts
    439

    Re: Fun C++ Problem

    Quote Originally Posted by whitevandal View Post
    i is DEcremented, not INcremented. So i will= -1, -2, -3...etc until it passes -20.
    Right, but if n = -20

    Then i < n will fail as 0 < -20 evaluates to false. Thus i will actually just equal 0, and "x" will be printing 0 times.

  3. #63
    Join Date
    Nov 2012
    Posts
    2

    Re: Fun C++ Problem

    There are four so far... anyone want to see them

    for (i=0; i+n; i--)
    for (i=0; i<n; n--)
    for (i=0;-i<n; i--)
    for (i=0;~i<n; i--)

    Neat question, not a very good introduction. Once someone finds three, they think they are a genius. Did someone find another?
    By the way, the unary NOT is replacing a space (" ") just like the negative symbol

  4. #64
    Join Date
    Nov 2012
    Posts
    2

    Re: Fun C++ Problem

    My bad, dumb, should've read the posts about the unary operator. Silly oversight, great problem for the class.

  5. #65
    Join Date
    Oct 2012
    Posts
    2

    Re: Fun C++ Problem

    What's wrong with this one?

    for (i=40; i<n; i--)

  6. #66
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,581

    Re: Fun C++ Problem

    Quote Originally Posted by shavarsh View Post
    What's wrong with this one?

    for (i=40; i<n; i--)
    This is a character insertion and as such it's against the rules which only allow changing existing characters.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  7. #67
    Join Date
    Oct 2012
    Posts
    2

    Re: Fun C++ Problem

    I'm not trying to be a smart ***, but this is not insertion?
    for (i=0;-i<n; i--)

    Or in this case, we substitute default-hidden '+' ?

  8. #68
    Join Date
    Jan 2009
    Posts
    596

    Re: Fun C++ Problem

    Quote Originally Posted by shavarsh View Post
    I'm not trying to be a smart ***, but this is not insertion?
    for (i=0;-i<n; i--)
    The original code has a space character where the minus sign now is - so it is replacing the space.

  9. #69
    Join Date
    Jun 2013
    Posts
    1

    Re: Fun C++ Problem

    Don't mean to show off but it took maybe 20 seconds. I can't imagine no one has got that on his quiz or whatever since 1999 that's absurd.

Page 5 of 5 FirstFirst ... 2345

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center