AP Computer Science 2.5 Review of the Basics
Recommendation
Want a study guide too?
Anyone know what the value of "q" is? We took it into a pawn shop, but the woman just looked at us funny.
AP | AP Computer Science |
AP Computer Science | Review of the Basics |
Computer Science | AP Computer Science |
Language | English Language |
Standard Operations and Algorithms | Operations on data structures |
Test Prep | AP Computer Science |
Transcript
handy counter let's start tracing this mess of spaghetti code and pass the
butter alright so if we look at the first if loop notice that it's testing
whether I is odd so for every odd value between 0 and 30 Q will increment go up
there are 15 odd values between 0 and 30 and since Q is already one well we know [odd values circled]
in the end that it must be at least 16 let's take a look at the second
if loop, it tests whether q is equal to some number / q well in this case some
number is 0 is 0 / 1 equal to 1 well no, it's equal to 0 though in the second
iteration for the for loop the second if loops doesn't execute it just kind of
sits there looking dumb.....all right well in fact we can [Man sitting looking at the ocean]
see that the only time the second if loop executes is when I equals 2 so in
this case Q also equals 2 and 2 times 2 over 2 definitely equals 2 so wow that's
a lot of two's from there however Q will always be greater than two times I thus
the if loop will never execute again this means that we have Q at a total of [hand crosses line through if loop]
17 so the answer is C well done that's using your noodle [Boy sat at a table with plate of noodles]