Input/Output for pairs of numbers: Difference between revisions
Input/Output for pairs of numbers (view source)
Revision as of 10:06, 1 September 2020
, 3 years agoAdded Wren
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
(Added Wren) |
||
Line 798:
out (int (+ ints<i> ints<(int (+ i 1))>)) endl p
end for</lang>
=={{header|Wren}}==
This assumes that both Stdin and Stdout are connected to a terminal.
<lang ecmascript>import "io" for Stdin
var output = Fn.new { |pairs| pairs.each { |p| System.print(p[0] + p[1]) } }
var n = Num.fromString(Stdin.readLine())
if (!n || !n.isInteger || n < 1) Fiber.abort("Number of pairs must be a positive integer.")
var pairs = []
for (i in 0...n) {
var line = Stdin.readLine()
var sp = line.split(" ")
if (sp.count != 2) Fiber.abort("Each line must contain 2 integers, separated by a space.")
var p1 = Num.fromString(sp[0])
if (!p1 || !p1.isInteger) Fiber.abort("First value is not an integer.")
var p2 = Num.fromString(sp[1])
if (!p2 || !p2.isInteger) Fiber.abort("Second value is not an integer.")
pairs.add([p1, p2])
}
System.print()
output.call(pairs)</lang>
{{out}}
Sample input/output:
<pre>
5
1 2
10 20
-3 5
100 2
5 5
3
30
2
102
10
</pre>
=={{header|zkl}}==
|