Input/Output for pairs of numbers: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(→‎{{header|OCaml}}: added ocaml)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 149:
Output for example input
 
<pre>
30
102
10
</pre>
 
=={{header|C sharp}}==
<lang csharp>using System;
using static System.Linq.Enumerable;
 
public class Program
static void Main(string[] args)
{
int count = Convert.ToInt32(Console.ReadLine());
for (int line = 0; line < count; line++) {
Console.WriteLine(Console.ReadLine().Split(' ').Sum(i => Convert.ToInt32(i)));
}
}
}</lang>
{{out}}
<pre>
3
Line 201 ⟶ 224:
5 5
 
30
102
10
</pre>
 
=={{header|C sharp}}==
<lang csharp>using System;
using static System.Linq.Enumerable;
 
public class Program
static void Main(string[] args)
{
int count = Convert.ToInt32(Console.ReadLine());
for (int line = 0; line < count; line++) {
Console.WriteLine(Console.ReadLine().Split(' ').Sum(i => Convert.ToInt32(i)));
}
}
}</lang>
{{out}}
<pre>
3
30
Line 311:
10
</pre>
 
=={{header|Haskell}}==
This solution will actually add any number of integers placed on each line. Additionally, after removing the bits of code that cut out the specified number of lines, the solution will sum any number of lines of integers.
 
<lang Haskell>main = do
contents <- getContents
let numberOfLines = read.head.lines$ contents
nums = map (map read.words).take numberOfLines.tail.lines$ contents
sums = map sum nums
mapM_ print sums</lang>
 
=={{header|Go}}==
Line 346 ⟶ 336:
}
}</lang>
 
=={{header|Haskell}}==
This solution will actually add any number of integers placed on each line. Additionally, after removing the bits of code that cut out the specified number of lines, the solution will sum any number of lines of integers.
 
<lang Haskell>main = do
contents <- getContents
let numberOfLines = read.head.lines$ contents
nums = map (map read.words).take numberOfLines.tail.lines$ contents
sums = map sum nums
mapM_ print sums</lang>
 
=={{header|J}}==
Line 387:
}
}</lang>
 
 
=={{header|Julia}}==
Line 451 ⟶ 450:
end
for _, result in pairs(intTab) do print(result) end</lang>
 
 
=={{header|OCaml}}==
Line 484 ⟶ 482:
10
</pre>
 
 
=={{header|PARI/GP}}==
Line 533 ⟶ 530:
print $a + $b . "\n";
}</lang>
 
=={{header|Perl 6}}==
<lang perl6>for ^get() { say [+] get.words }</lang>
This does more than the task asks. It will sum as many numbers as you care to put on each line, and the numbers need not be integers, but may also be a mix of rational, floating-point, or complex numbers. More subtly, <tt>get</tt> can read from a file specified as a command-line argument, but defaults to taking STDIN if no filename is specified.
 
=={{header|Phix}}==
Line 653 ⟶ 646:
(map string->number
(string-split (read-line))))))</lang>
 
=={{header|Perl 6Raku}}==
(formerly Perl 6)
<lang perl6>for ^get() { say [+] get.words }</lang>
This does more than the task asks. It will sum as many numbers as you care to put on each line, and the numbers need not be integers, but may also be a mix of rational, floating-point, or complex numbers. More subtly, <tt>get</tt> can read from a file specified as a command-line argument, but defaults to taking STDIN if no filename is specified.
 
=={{header|REXX}}==
Line 742 ⟶ 740:
}
</lang>
 
=={{header|Tcl}}==
<lang tcl>gets stdin n
10,333

edits