Two sum: Difference between revisions

Added XPL0 example.
(Added XPL0 example.)
Line 2,676:
 
Indices: [0, 4] sum to 90 (0 + 90 = 90)
</pre>
 
=={{header|XPL0}}==
Test cases from Algol 68.
<lang XPL0>proc TwoSum(Size, Array, Sum);
int Size, Array, Sum, I, J;
[Text(0, "[");
for I:= 0 to Size-1 do
for J:= I+1 to Size-1 do
if Array(I) + Array(J) = Sum then
[IntOut(0, I); Text(0, ", "); IntOut(0, J);
J:= Size; I:= Size;
];
Text(0, "]^m^j");
];
 
[TwoSum(5, [ 0, 2, 11, 19, 90], 21); \ should be [1, 3]
TwoSum(7, [-8, -2, 0, 1, 5, 8, 11], 3); \ should be [0, 6] (or [1, 4])
TwoSum(7, [-3, -2, 0, 1, 5, 8, 11], 17); \ should be []
TwoSum(7, [-8, -2, -1, 1, 5, 9, 11], 0); \ should be [2, 3]
]</lang>
 
{{out}}
<pre>
[1, 3]
[0, 6]
[]
[2, 3]
</pre>
 
772

edits