Computer Science – 9.2 Algorithms | e-Consult
9.2 Algorithms (1 questions)
Login to see all questions.
Click on a question to view the answer
Stepwise Refinement for Calculating the Area of a Rectangle:
- Initial Outline (High-Level): Calculate the area of a rectangle by multiplying its length and width.
- Refinement 1: Identify Inputs and Outputs. The algorithm requires the length and width of the rectangle as input and the area as output.
- Refinement 2: Breakdown the Calculation. The core calculation is multiplication. We need to specify how to obtain the length and width. Assume these are provided as input values.
- Refinement 3: Detailed Steps.
- Get the length of the rectangle from the input.
- Get the width of the rectangle from the input.
- Multiply the length and width together.
- The result of the multiplication is the area of the rectangle.
- Output the calculated area.
| Input: Length, Width |
| Calculate Area = Length * Width |
| Output: Area |