Two sum: Difference between revisions

Content deleted Content added
Loren (talk | contribs)
Added XPL0 example.
Galileo (talk | contribs)
Line 2,705:
[2, 3]
</pre>
 
=={{header|Yabasic}}==
{{trans|FreeBASIC}}
<lang Yabasic>// Rosetta Code problem: http://rosettacode.org/wiki/Two_sum
// by Galileo, 04/2022
Sub twoSum (a(), b(), targetSum)
local ub, sum, i, j
ub = arraysize(a(), 1)
For i = 1 To ub - 1
If a(i) <= targetSum Then
For j = i + 1 To ub
sum = a(i) + a(j)
If sum = targetSum Then
Redim b(2)
b(1) = i : b(2) = j
Return
ElsIf sum > targetSum Then
break
EndIf
Next j
Else
break
EndIf
Next i
End Sub
Dim a(5)
Dim b(1)
data 0, 2, 11, 19, 90
for n = 1 to 5 : read a(n) : next
targetSum = 21
twoSum(a(), b(), targetSum)
If arraysize(b(), 1) = 1 Then
Print "No two numbers were found whose sum is ", targetSum
Else
Print "The numbers with indices ", b(1), " and ", b(2), " sum to ", targetSum
End If</lang>
{{out}}
<pre>The numbers with indices 2 and 4 sum to 21
---Program done, press RETURN---</pre>
 
=={{header|zkl}}==