Last list item: Difference between revisions
→{{header|ALGOL 68}}: Revised to meet the task requirements re the positioning of the new element
(→{{header|ALGOL 68}}: Revised to meet the task requirements re the positioning of the new element) |
|||
Line 10:
=={{header|ALGOL 68}}==
Was a translation of the sorted Wren version but the sorting has been removed as per the revised task requirements.
<lang algol68>BEGIN # find the last element after
# of the two smallest elements and removing them #
[ 1 : 9 ]INT a := ( 6, 81, 243, 14, 25, 49, 123, 69, 11 );
Line 35 ⟶ 34:
)
);
FOR i
IF i /= s1pos AND i /= s2pos THEN a[ m pos +:= 1 ] := a[ i ] FI
OD;
a[ m pos + 1 ] := sum;
a count -:= 1
OD;
print( ( "Last item is ", whole( a[ 1 ], 0 ), ".", newline ) )
END
</lang>
{{out}}
<pre>
List: 6 81 243 14 25 49 123 69 11; two smallest: 6 @ 1 and 11 @ 9; sum = 17
List:
List: 81 243
List: 81 243
List: 81 243
List: 243
List: 243
List: 243 378; two smallest: 243 @ 1 and 378 @ 2; sum = 621
Last item is 621.
|