Free sample SI units
The flowchart shown is part of a routine in a test-rig controller. It sets S = 0 and K = 1, then repeatedly replaces S with S + K² and K with K + 2, testing after each pass whether K > 7; when the test is true it outputs S and stops. The value of S that the routine outputs is most nearly:
Swipe the diagram sideways to see all of it.
- A16
- B35
- C49
- D84
Work it out first. On the exam you would have about three minutes.
Show the answer and worked solutionHide the answer and worked solution
AnswerD84
Find it in the Handbook
Electrical and Computer Engineering
Flowchart Definition
Flowchart symbols (process operation, decision, data I/O, start or stop point) from the Handbook; tracing the loop pass by pass (standard method; the Handbook has no formula for it)
Search (Ctrl+F)
Given
- Start: ,
- Loop: , then , then test
- Output when the test is true
Find
The value of that is output
Trace the passes
Pass 1: , . Pass 2: , . Pass 3: , ; is false, so loop again.
Last pass and output
Pass 4: , ; is true, so the routine outputs .
Why the other choices are wrong
- A16 comes from adding instead of : . The process box squares the counter before adding it, so the sum is .
- B35 comes from stopping when reaches 7, as if the test were . The test is , and 7 is not greater than 7, so the loop runs a fourth time and adds , giving 84.
- C49 is only the last term, , as if each pass replaced with . The box adds to the running total, so accumulates .
Exam-day tip
Trace a loop in a table with one row per pass and one column per variable, and write the decision result (true or false) in each row. Pay special attention to the pass where the counter first equals the limit: a strict test such as lets that pass loop again.