What does this algorithm output?
count = 0for i = 3 to 15 step 4count = count + 1next iprint(count)
OCR 2.2.1 · Programming
OCR J277 questions. AQA · OCR · The lesson
What does this algorithm output?
count = 0for i = 3 to 15 step 4count = count + 1next iprint(count)
A program asks for a password until the user types the right one. Which kind of loop fits best?
What does this algorithm output?
n = 10don = n + 5until n > 8print(n)
What does this algorithm output?
total = 0x = 12while x < 10total = total + xx = x + 1endwhileprint(total)
What does this algorithm output?
stars = 0for row = 1 to 3for col = 1 to rowstars = stars + 1next colnext rowprint(stars)
The algorithm adds square numbers until the total reaches 20 or more.
total = 0n = 1while total < 20total = total + n * nn = n + 1endwhileprint(n)
the trace table. Write a value only when it changes; the first row is done for you.
| total | n | Output |
|---|---|---|
| 0 | 1 | |
how many times the loop body runs.
why a condition-controlled loop is used here rather than a count-controlled loop.
A program must ask the user for ten whole numbers, one at a time, and output the total of the numbers that are greater than 0.
the program. You may use pseudo-code or a high-level language such as Python.