11.3 Structured Programming (3)

Resources | Revision Questions | Computer Science

Login to see all questions

Click on a question to view the answer

1.

Explain where in the construction of an algorithm it is appropriate to use a function. Consider the benefits and potential drawbacks of using functions.

2.

Define what a procedure is in programming and explain the benefits of using procedures (also known as functions or subroutines). Provide a simple example of a procedure in any programming language of your choice.

3.

A student has written the following code in a programming language (you do not need to identify the specific language). The code is intended to calculate the sum of the first 'n' natural numbers. Identify the potential problems with this code in terms of its design and explain how a procedure could be used to improve it. Provide a brief example of how the improved code might look.

  sum = 0
  for i = 1 to n
    sum = sum + i
  print sum