Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A program draws borders of stars with a procedure.
PROCEDURE Border(Width : INTEGER)
DECLARE Count : INTEGER
FOR Count ← 1 TO Width
OUTPUT '*'
NEXT Count
ENDPROCEDURE
CALL Border(4)
CALL Border(7)How many stars are output in all? Then write one more line that draws a border of 10 stars, and say why it uses CALL.
A procedure does a job: PROCEDURE Name(Param : TYPE) ... ENDPROCEDURE, run with CALL Name(value). A function returns one value: FUNCTION Name(Param : TYPE) RETURNS TYPE ... RETURN value ... ENDFUNCTION, used inside an expression without CALL. A variable declared inside a subroutine is local; one declared in the main program is global.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Step 1. The first call. Width is 4, so 4 stars are output.
Step 2. The second call. Width is 7, so 7 more stars are output. In all, stars.
Step 3. The new line.
CALL Border(10)Why CALL. Border is a procedure. It does a job and returns no value, so it is called as a statement on its own with CALL.
Answer: 11 stars.
Log in to join the discussion.
Loading…