Input/Output for pairs of numbers: Difference between revisions

Added BBC BASIC
(Added FreeBASIC)
(Added BBC BASIC)
Line 64:
NR > n+1 {exit}
{print $1+$2}</lang>
 
=={{header|BBC BASIC}}==
The specification is a bit ambiguous, but I understood it as wanting us to read all the numbers in <i>first</i> and then print all the sums. This program does that. It could be a couple of lines shorter if we were allowed to use a comma instead of a space as separator.
<lang bbcbasic>INPUT n%
DIM pairs%(n% - 1, 1)
FOR i% = 0 TO n% - 1
INPUT s$
pairs%(i%, 0) = VAL(LEFT$(s$, INSTR(s$, " ")))
pairs%(i%, 1) = VAL(MID$(s$, INSTR(s$, " ")))
NEXT
FOR i% = 0 TO n% - 1
PRINT pairs%(i%, 0) + pairs%(i%, 1)
NEXT</lang>
With the sample inputs:
<pre>?5
?1 2
?10 20
?-3 5
?100 2
?5 5
3
30
2
102
10</pre>
 
=={{header|C}}==
519

edits