5 7 5 6 8 5 6 6 7 9 5 7 |
% 4a) Why might length be a bad name for the parameter? procedure putArea(length, width : real) put "The area of the rectangle is ", round(length * width) end putArea % 4b) var l, w : real put "Enter the length" get l put "Enter the width" get w putArea(l, w)
procedure putRow(c : char, n : int) for i : 1 .. n put c.. end for end putRow
const WIDTH := 80 procedure putRow(c : char, n : int) for i : 1 .. n put c.. end for end putRow procedure putTriangle(rows : int, symbol : char) for i : 1 .. rows put " ":WIDTH div 2 - i.. putRow(symbol, 1 + 2*(i - 1)) put "" end for end putTriangle put "A small triangle of stars" putTriangle(3, '*') put "" put "A large triangle of plus signs" putTriangle(10, '+') put "" put "A very small triangle of dots" putTriangle(1, '.') put ""
procedure range (list: array 1 .. * of int) var least, greatest : int least := list(1) greatest := list(1) for i : 1 .. upper(list) if list(i) < least then least := list(i) end if if list(i) > greatest then greatest := list(i) end if end for put "The least value is ", least, " and the greatest is ", greatest end range