A+B: Difference between revisions
Zig added
m (→GUI version: added libheader) |
(Zig added) |
||
(9 intermediate revisions by 8 users not shown) | |||
Line 1,412:
=={{header|AWK}}==
<syntaxhighlight lang="awk">{print $1 + $2}</syntaxhighlight>
=={{header|BabyCobol}}==
* NB: COBOL's ACCEPT does not work with multiple identifiers
IDENTIFICATION DIVISION.
PROGRAM-ID. PLUS.
DATA DIVISION.
01 A PICTURE IS S9999.
01 B LIKE A.
PROCEDURE DIVISION.
DISPLAY "Enter two numbers: " WITH NO ADVANCING.
ACCEPT A B.
ADD A TO B.
DISPLAY "A+B =" B.
</syntaxhighlight>▼
=={{header|BASIC}}==
Line 1,818 ⟶ 1,833:
<syntaxhighlight lang="brat">numbers = g.split[0,1].map(:to_i)
p numbers[0] + numbers[1] #Prints the sum of the input</syntaxhighlight>
=={{header|Bruijn}}==
<syntaxhighlight lang="bruijn">
:import std/Combinator .
:import std/String .
:import std/Number .
:import std/Char C
main (split-by (C.eq? ' ')) → &(add ⋔ string→number)
</syntaxhighlight>
=={{header|Burlesque}}==
Line 2,314 ⟶ 2,339:
=={{header|EasyLang}}==
<syntaxhighlight
repeat
while i < len a$ and substr a$ i 1 <> " "▼
i += 1
.
a = number substr a$ 1 i
b = number substr a$ i
print a + b
</syntaxhighlight>
Line 2,694 ⟶ 2,720:
=={{header|Euler}}==
'''begin'''▼
▲<syntaxhighlight lang="euler">
'''out''' '''in''' + '''in'''▼
▲begin
'''end''' $▼
▲ out in + in
▲end $
▲</syntaxhighlight>
=={{header|Euler Math Toolbox}}==
Line 2,787 ⟶ 2,811:
PAUSE</syntaxhighlight>
=={{header|Fennel}}==
{{trans|Lua}}
<syntaxhighlight lang="fennel">
(let [(a b) (io.read :*number :*number)]
(print (+ a b)))
</syntaxhighlight>
=={{header|Fhidwfe}}==
Line 4,439 ⟶ 4,470:
File input:
<syntaxhighlight lang="parigp">read("file1")+read("file2")</syntaxhighlight>
=={{header|PascalABC.NET}}==
<syntaxhighlight lang="pascal">
##
var (a,b) := ReadInteger2;
Writeln(a + b);
</syntaxhighlight>
=={{header|Pascal}}==
Line 5,275 ⟶ 5,314:
More idiomatically:
<syntaxhighlight lang="ruby">say read(String).words»to_i
Explicit summation:
Line 6,084 ⟶ 6,123:
=={{header|Wren}}==
<syntaxhighlight lang="
while (true) {
Line 6,294 ⟶ 6,333:
#true
(001) "read"</syntaxhighlight>
=={{header|Zig}}==
<syntaxhighlight lang="zig">
const std = @import("std");
const stdout = std.io.getStdOut().writer();
const Input = enum { a, b };
pub fn main() !void {
var buf: [1024]u8 = undefined;
const reader = std.io.getStdIn().reader();
const input = try reader.readUntilDelimiter(&buf, '\n');
const values = std.mem.trim(u8, input, "\x20");
var count: usize = 0;
var split: usize = 0;
for (values, 0..) |c, i| {
if (!std.ascii.isDigit(c)) {
count += 1;
if (count == 1) split = i;
}
}
const a = try std.fmt.parseInt(u64, values[0..split], 10);
const b = try std.fmt.parseInt(u64, values[split + count ..], 10);
try stdout.print("{d}\n", .{a + b});
}
</syntaxhighlight>
{{out}}
<pre>
1 2
3
3 6
9
</pre>
=={{header|zkl}}==
|