Before writing code, a good programmer plans. Decomposition breaks a problem into smaller parts, and abstraction keeps only the details that matter. The plan becomes an algorithm, written as a flowchart or in pseudocode. Standard methods solve common tasks: linear search, bubble sort, totalling, counting and finding the largest or smallest value. Validation checks that input is sensible, and verification checks that it was entered correctly. A trace table follows an algorithm step by step to find its output or its errors. Testing with normal, abnormal, extreme and boundary data shows whether it works.
Lessons, worked problems and more questions on Algorithms and Problem-Solving →A and B to be whole numbers, with B not negative. In one sentence, what does this algorithm compute?
INPUT A
INPUT B
WHILE B > 0 DO
A ← A + 1
B ← B - 1
ENDWHILE
OUTPUT AA and takes from B. The loop runs B times, so A grows by B. For and the output is .
Nothing is multiplied. B is counted down, not taken from A. A gains on every pass, not just once.Log in to join the discussion.
Loading…