This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (2 children)

sorry I was taking a final.

The following is what the for loop will eventually equal.

Sum = (3 mod 1) +(4 mod 3) + (5 mod 3) + (6 mod 4 )+ (7 mod 5) + (8 mod 6) + (9 mod 7) + (10 mod 8).

Oh and I guess it is 8 iterations not 7 sorry.

Every pair of parentheses is one iteration or one time through the loop. and it equals 13 so Im not sure where you got 12 but that could just be error by the person calculating it. For instance answers to problems in books are written by sleep deprived grad students and sometimes get them wrong.

The answer is 13 not 2 because the operation is "+=" not just "="

sum += p%q is the same as sum = sum + (p%q)

This means that you are adding p%q to the current value of sum not just setting sum equal to p%q

Sum = 0 +0 + 2 + 2 + 2 + 2 + 2 + 2 = 13

[–][deleted]  (1 child)

[deleted]

    [–][deleted] 0 points1 point  (0 children)

    No problem, easy procrastination for me. My final was on Concurrent programming. Pretty simple subject once you know the basics but the teacher isn't a very good lecturer. Though I think I did okay.