A+B: Difference between revisions

11,618 bytes added ,  1 month ago
m (syntax highlighting fixup automation)
(42 intermediate revisions by 30 users not shown)
Line 32:
 
=={{header|0815}}==
<syntaxhighlight lang="0815">|x|+%</syntaxhighlight>
 
=={{header|11l}}==
{{trans|Python}}
<syntaxhighlight lang="11l">print(sum(input().split(‘ ’, group_delimiters' 1B).map(i -> Int(i))))</syntaxhighlight>
 
=={{header|360 Assembly}}==
<syntaxhighlight lang="360asm">* A+B 29/08/2015
APLUSB CSECT
USING APLUSB,R12
Line 75:
 
=={{header|8th}}==
<syntaxhighlight lang="forth">gets dup . space eval n:+ . cr</syntaxhighlight>
 
=={{header|8080 Assembly}}==
Line 86:
which can take four forms:
 
<syntaxhighlight lang="8080asm"> dad b ; HL += BC (i.e., add BC reg pair to HL reg pair)
dad d ; HL += DE
dad h ; HL += HL (also known as "mul HL by two")
Line 93:
Merely doing A+B, with 16-bit numbers so that <math>(-1000 \le A,B \le +1000)</math> will fit,
would look like this:
<syntaxhighlight lang="8080asm"> lxi h,123
lxi d,456
dad d
Line 104:
fits exactly in one CP/M block.
 
<syntaxhighlight lang="8080asm">fcb1n: equ 5Ch+1 ; "Filename" in first FCB
fcb2n: equ 6Ch+1 ; "Filename" in second FCB
puts: equ 9 ; CP/M call to write string to console
Line 209:
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang=AArch64"aarch64 Assemblyassembly">
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program addAetB.s */
Line 409:
 
=={{header|ABAP}}==
<syntaxhighlight lang=ABAP"abap">report z_sum_a_b.
data: lv_output type i.
selection-screen begin of block input.
Line 424:
lv_output = p_first + p_second.
write : / lv_output.</syntaxhighlight>
 
=={{header|Acornsoft Lisp}}==
{{trans|Common Lisp}}
 
<pre>
Evaluate: (print (plus (read) (read)))
3 2
5
</pre>
 
=={{header|Action!}}==
<syntaxhighlight lang=Action"action!">BYTE FUNC Find(CHAR ARRAY s CHAR c BYTE POINTER err)
BYTE i
FOR i=1 TO s(0)
Line 503 ⟶ 512:
 
=={{header|Ada}}==
<syntaxhighlight lang=Ada"ada">-- Standard I/O Streams
 
with Ada.Integer_Text_Io;
Line 514 ⟶ 523:
end APlusB;</syntaxhighlight>
Using appropriate user defined types:
<syntaxhighlight lang=Ada"ada">with Ada.Text_IO;
 
procedure A_Plus_B is
Line 529 ⟶ 538:
=={{header|Agena}}==
Tested with Agena 2.9.5 Win32
<syntaxhighlight lang="agena">scope
local f := trim( io.read() ) split " "; # read a line and split into fields
local a := tonumber( f[ 1 ] );
Line 537 ⟶ 546:
 
=={{header|Aime}}==
<syntaxhighlight lang="aime">file f;
list l;
 
Line 547 ⟶ 556:
=={{header|ALGOL 60}}==
{{works with|A60}}
<syntaxhighlight lang="algol60">begin
comment A+B;
integer a,b;
Line 569 ⟶ 578:
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - missing transput function "read int"}}
===Console===
<syntaxhighlight lang="algol68">print((read int + read int))</syntaxhighlight>
Input:
<pre>
Line 580 ⟶ 589:
 
===File===
<syntaxhighlight lang="algol68">open(stand in, "input.txt", stand in channel);
open(stand out, "output.txt", stand out channel);
print((read int + read int))</syntaxhighlight>
Line 593 ⟶ 602:
 
=={{header|ALGOL W}}==
<syntaxhighlight lang="algolw">begin
integer a, b;
read( a, b );
Line 600 ⟶ 609:
 
=={{header|Amazing Hopper}}==
<syntaxhighlight lang=Amazing"amazing Hopperhopper">
#include <hbasic.h>
 
Line 625 ⟶ 634:
Version dos: hopper-BASIC acepta "programación fluída"
 
<syntaxhighlight lang=Amazing"amazing Hopperhopper">
#include <hbasic.h>
 
Line 660 ⟶ 669:
 
=={{header|Apex}}==
<syntaxhighlight lang=Apex"apex">
 
static Integer sumOfTwoNums(Integer A, Integer B) {
Line 680 ⟶ 689:
 
=={{header|APL}}==
<syntaxhighlight lang=APL"apl"> ⎕+⎕ </syntaxhighlight>
 
=={{header|AppleScript}}==
Open the '''AppleScript Editor''' and save this as '''A+B.scpt''' on your Desktop
<syntaxhighlight lang=AppleScript"applescript">on run argv
try
return ((first item of argv) as integer) + (second item of argv) as integer
Line 700 ⟶ 709:
 
=={{header|Arc}}==
<syntaxhighlight lang=Arc"arc">
(prn (+ (read)
(read)))
Line 708 ⟶ 717:
{{trans|C}}
{{works with|Argile|1.0.0}}
<syntaxhighlight lang=Argile"argile">(: Standard input-output streams :)
use std, array
Cfunc scanf "%d%d" (&val int a) (&val int b)
printf "%d\n" (a + b)</syntaxhighlight>
<syntaxhighlight lang=Argile"argile">(: Input file : input.txt :)
(: Output file: output.txt :)
use std, array
Line 727 ⟶ 736:
Exploiting C standard library functions (scanf and printf).
Requires arm-linux-gnueabi-gcc and qemu-arm. Compile with:
<syntaxhighlight lang=ARM_Assembly"arm_assembly">arm-linux-gnueabi-as src.s -o src.o && arm-linux-gnueabi-gcc -static src.o -o run && qemu-arm run</syntaxhighlight>
 
<syntaxhighlight lang=ARM_Assembly"arm_assembly">.text
.global main
.extern printf
Line 775 ⟶ 784:
Save in ab.S
Build with:
<syntaxhighlight lang=ARM_Assembly"arm_assembly">as -o ab.o ab.S
ld -o a.out ab.o</syntaxhighlight>
 
<syntaxhighlight lang=ARM_Assembly"arm_assembly">.data
.align 2
.code 32
Line 1,295 ⟶ 1,304:
=={{header|Arturo}}==
 
<syntaxhighlight lang="rebol">while ø [
x: map split.words input "give me 2 numbers:" 'x -> to :integer x
print add x\0 x\1
Line 1,309 ⟶ 1,318:
 
=={{header|AsciiDots}}==
<<syntaxhighlight lang="asciidots">
<Lang AsciiDots>
&-#$-\
.-#?-[+]
.-#?--/
</syntaxhighlight>
</Lang>
 
=={{header|ATS}}==
<syntaxhighlight lang=ATS"ats">
(* ****** ****** *)
//
Line 1,347 ⟶ 1,356:
=={{header|AutoHotkey}}==
This handles more than two inputs
<syntaxhighlight lang=AutoHotkey"autohotkey">Gui, Add, Edit, vEdit ;Enter your A+B, i.e. 5+3 or 5+3+1+4+6+2
Gui, Add, Button, gAdd, Add
Gui, Add, Edit, ReadOnly x+10 w80
Line 1,362 ⟶ 1,371:
 
=={{header|AutoIt}}==
<syntaxhighlight lang=AutoIt"autoit">;AutoIt Version: 3.2.10.0
$num = "45 54"
consolewrite ("Sum of " & $num & " is: " & sum($num))
Line 1,372 ⟶ 1,381:
===Example2===
This version can handle any amount of numbers in the input:
<syntaxhighlight lang=AutoIt"autoit">ConsoleWrite("# A+B:" & @CRLF)
 
Func Sum($inp)
Line 1,402 ⟶ 1,411:
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">{print $1 + $2}</syntaxhighlight>
 
=={{header|BabyCobol}}==
<syntaxhighlight lang="cobol">
* 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}}==
<syntaxhighlight lang="qbasic">DEFINT A-Z
 
tryagain:
Line 1,423 ⟶ 1,447:
 
==={{header|Applesoft BASIC}}===
<syntaxhighlight lang=ApplesoftBasic"applesoftbasic">10 BH = PEEK(37)
20 INPUT ""; A$ : I$ = A$ : VTAB BH : A = PEEK(40) + PEEK(41) * 256 : FOR S = 0 TO 39 : IF PEEK(A + S) = 160 THEN NEXT S : S = 0
40 IF LEN(I$) THEN IF MID$(I$, LEN(I$), 1) = " " THEN I$ = MID$(I$, 1, LEN(I$) - 1) : GOTO 40RTRIM
Line 1,436 ⟶ 1,460:
 
==={{header|BaCon}}===
<syntaxhighlight lang="qbasic">' A+B
INPUT d$
PRINT VAL(TOKEN$(d$, 1)) + VAL(TOKEN$(d$, 2))</syntaxhighlight>
 
==={{header|BASIC256}}===
<syntaxhighlight lang="basic256">dim a(2)
input "Enter two numbers separated by a space?", t$
a = explode(t$," ")
Line 1,447 ⟶ 1,471:
 
==={{header|BBC BASIC}}===
<syntaxhighlight lang="bbc"> REPEAT
hereY% = VPOS
INPUT LINE "" q$
Line 1,462 ⟶ 1,486:
UNTIL FALSE</syntaxhighlight>
That seems overly complicated. What's wrong with:
<syntaxhighlight lang="bbc"> REPEAT
INPUT LINE "" q$
space% = INSTR(q$," ")
PRINT VAL LEFT$(q$,space%-1) + VAL MID$(q$,space%+1)
UNTIL FALSE</syntaxhighlight>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
{{works with|Applesoft BASIC}}
{{works with|GW-BASIC}}
{{works with|MSX_BASIC}}
{{works with|PC-BASIC|any}}
{{works with|QBasic}}
<syntaxhighlight lang="qbasic">10 CLS : rem 10 HOME for Applesoft BASIC
20 PRINT "ENTER TWO NUMBERS, SEPARATED BY A SPACE: ";
30 INPUT X$
40 I = 1 : N = LEN(X$)
50 IF MID$(X$, I, 1) <> " " AND I < N THEN I = I + 1 : GOTO 50
60 A = VAL(LEFT$(X$, I))
70 B = VAL(RIGHT$(X$, N - 1))
80 PRINT A + B
90 END</syntaxhighlight>
 
==={{header|Commodore BASIC}}===
<syntaxhighlight lang="qbasic">10 PRINT "ENTER TWO NUMBERS, SEPARATED BY A SPACE: ";
20 INPUT X$
30 I = 1 : N = LEN(X$)
Line 1,478 ⟶ 1,519:
 
==={{header|FreeBASIC}}===
<syntaxhighlight lang="freebasic">' fb 1.05.0 Win64
 
Dim As Integer a, b
Line 1,495 ⟶ 1,536:
Print "Press any key to quit the program"
Sleep</syntaxhighlight>
 
==={{header|GW-BASIC}}===
The [[#Chipmunk_Basic|Chipmunk Basic]] solution works without any changes.
 
==={{header|FUZE BASIC}}===
<syntaxhighlight lang="qbasic">INPUT n$
PRINT VAL(LEFT$(n$,(LEN(STR$(VAL(n$))))))+VAL(RIGHT$(n$,(LEN(n$)-LEN(STR$(VAL(n$)))-1)))
END</syntaxhighlight>
 
==={{header|IS-BASIC}}===
<syntaxhighlight lang=IS"is-BASICbasic">100 DO
110 INPUT PROMPT "Ener two integers separated by a comma: ":A,B
120 IF ABS(A)>1000 OR ABS(B)>1000 OR IP(A)<>A OR IP(B)<>B THEN
Line 1,513 ⟶ 1,557:
 
==={{header|Liberty BASIC}}===
<syntaxhighlight lang="lb">input, n$
print eval(word$(n$,1);" + ";word$(n$,2))</syntaxhighlight>
 
==={{header|Minimal BASIC}}===
{{works with|QBasic}}
{{works with|QuickBasic}}
{{works with|Applesoft BASIC}}
{{works with|BASICA}}
{{works with|Chipmunk Basic}}
{{works with|GW-BASIC}}
{{works with|IS-BASIC}}
{{works with|MSX Basic}}
{{works with|Just BASIC}}
{{works with|Liberty BASIC}}
{{works with|Run BASIC}}
{{works with|Yabasic}}
<syntaxhighlight lang="qbasic">10 PRINT "ENTER NUMBER A";
20 INPUT A
30 PRINT "ENTER NUMBER B";
40 INPUT B
50 PRINT A+B
60 END</syntaxhighlight>
 
==={{header|MSX Basic}}===
The [[#Chipmunk_Basic|Chipmunk Basic]] solution works without any changes.
 
==={{header|OxygenBasic}}===
<syntaxhighlight lang="text">
uses console
int i
Line 1,533 ⟶ 1,600:
 
==={{header|Sinclair ZX81 BASIC}}===
<syntaxhighlight lang="basic">10 INPUT A$
20 LET I=1
30 IF A$(I)=" " THEN GOTO 60
Line 1,539 ⟶ 1,606:
50 GOTO 30
60 PRINT VAL A$( TO I-1)+VAL A$(I+1 TO )</syntaxhighlight>
 
==={{header|SmallBASIC}}===
<syntaxhighlight lang="SmallBASIC">
input "Enter number A: "; a
input "Enter number B: "; b
print "A + B = "; a + b
</syntaxhighlight>
 
==={{Header|Tiny BASIC}}===
<syntaxhighlight lang=Tiny"tiny BASICbasic">REM Rosetta Code problem: https://rosettacode.org/wiki/A+B
REM by Jjuanhdez, 06/2022
 
Line 1,561 ⟶ 1,635:
 
==={{header|True BASIC}}===
<syntaxhighlight lang="qbasic">DO
INPUT PROMPT "Enter two integers separated by a comma: ": A, B
IF ABS(A)>1000 OR ABS(B)>1000 OR IP(A)<>A OR IP(B)<>B THEN
Line 1,573 ⟶ 1,647:
END</syntaxhighlight>
==={{header|uBasic/4tH}}===
<syntaxhighlight lang="text">s = FUNC(_GetInt(1000)) + FUNC(_GetInt(1000))
Print "The sum is: ";s
End
Line 1,587 ⟶ 1,661:
Loop
Return (b@)</syntaxhighlight>
 
==={{header|XBasic}}===
{{works with|Windows XBasic}}
<syntaxhighlight lang="qbasic">PROGRAM "A+B"
VERSION "0.0000"
 
DECLARE FUNCTION Entry ()
 
FUNCTION Entry ()
a$ = INLINE$("Enter integer A: ")
a = SLONG(a$)
b$ = INLINE$("Enter integer B: ")
b = SLONG(b$)
DO WHILE 1
IF ABS(a) > 1000 OR ABS(b) > 1000 THEN
PRINT "Both integers must be in the interval [-1000..1000] - try again."
PRINT
ELSE
PRINT "Their sum is"; a + b
EXIT DO
END IF
LOOP
END FUNCTION
END PROGRAM</syntaxhighlight>
 
=={{header|Batch File}}==
Prompts version
<syntaxhighlight lang="dos">::aplusb.cmd
@echo off
setlocal
Line 1,599 ⟶ 1,697:
endlocal</syntaxhighlight>
All on the commandline version
<syntaxhighlight lang="dos">::aplusb.cmd
@echo off
setlocal
Line 1,608 ⟶ 1,706:
endlocal</syntaxhighlight>
Formula on the command line version
<syntaxhighlight lang="dos">::aplusb.cmd
@echo off
setlocal
Line 1,622 ⟶ 1,720:
</pre>
Parse the input stream version (thanks to Tom Lavedas on alt.msdos.batch.nt)
<syntaxhighlight lang="dos">::aplusb.cmd
@echo off
setlocal
Line 1,645 ⟶ 1,743:
=={{header|bc}}==
{{Works with|GNU bc}}
<syntaxhighlight lang="bc">read() + read()</syntaxhighlight>
 
=={{header|Befunge}}==
<syntaxhighlight lang="befunge">&&+.@</syntaxhighlight>
 
=={{header|Bird}}==
<syntaxhighlight lang=Bird"bird">use Console Math
 
define Main
Line 1,661 ⟶ 1,759:
=={{header|BlooP}}==
BlooP and FlooP can't actually read from stdin, but here's the procedure it would use, if it could.
<syntaxhighlight lang="bloop">
<Lang BlooP>
DEFINE PROCEDURE ''ADD'' [A, B]:
BLOCK 0: BEGIN
OUTPUT <= A + B;
BLOCK 0: END.
</syntaxhighlight>
</Lang>
 
=={{header|bootBASIC}}==
Both numbers are entered separately.
<syntaxhighlight lang=bootBASIC"bootbasic">10 print "Number 1";
20 input a
30 print "Number 2";
Line 1,680 ⟶ 1,778:
{{works with|https://github.com/dzaima/CBQN CBQN}}
 
<syntaxhighlight lang="bqn">#!/usr/bin/env bqn
 
# Cut 𝕩 at occurrences of 𝕨, removing separators and empty segments
Line 1,697 ⟶ 1,795:
=={{header|Bracmat}}==
<code>filter</code> is a pattern that checks that input is a non-fractional number not less than -1000 and not greater than 1000. The filter is applied to each input.
<syntaxhighlight lang="bracmat">( out
$ ( put$"Enter two integer numbers between -1000 and 1000:"
& (filter=~/#%:~<-1000:~>1000)
Line 1,707 ⟶ 1,805:
 
=={{header|Brainf***}}==
<syntaxhighlight lang="brainf***">INPUT AND SUMMATION
TODO if first symbol is a minus sign print Qgo awayQ
+> initialize sum to one
Line 1,733 ⟶ 1,831:
 
=={{header|Brat}}==
<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}}==
<syntaxhighlight lang="burlesque">ps++</syntaxhighlight>
 
=={{header|C}}==
<syntaxhighlight lang="c">// Standard input-output streams
#include <stdio.h>
int main()
Line 1,749 ⟶ 1,857:
return 0;
}</syntaxhighlight>
<syntaxhighlight lang="c">// Input file: input.txt
// Output file: output.txt
#include <stdio.h>
Line 1,761 ⟶ 1,869:
return 0;
}</syntaxhighlight>
<syntaxhighlight lang="c">
#include <stdio.h>
#include <stdlib.h>
Line 1,772 ⟶ 1,880:
 
=={{header|C sharp|C#}}==
<syntaxhighlight lang="csharp">using System;
using System.Linq;
 
Line 1,783 ⟶ 1,891:
}</syntaxhighlight>
Another way (not recommended since it does not work with more than two numbers):
<syntaxhighlight lang="csharp">using System;
 
class Program
Line 1,799 ⟶ 1,907:
 
=={{header|C++}}==
<syntaxhighlight lang="cpp">// Standard input-output streams
#include <iostream>
using namespace std;
Line 1,808 ⟶ 1,916:
cout << a + b << endl;
}</syntaxhighlight>
<syntaxhighlight lang="cpp">// Input file: input.txt
// Output file: output.txt
#include <fstream>
Line 1,823 ⟶ 1,931:
 
=={{header|Ceylon}}==
<syntaxhighlight lang="ceylon">shared void run() {
 
print("please enter two numbers for me to add");
Line 1,848 ⟶ 1,956:
}
}</syntaxhighlight>
 
=={{header|CFEngine}}==
There is no concept of CFEngine policy reading from stdin so I will read from a file.
 
<syntaxhighlight lang="cfengine">
$ cat sum.cf
bundle agent main
{
vars:
"line_count" int => readintarray(
"input",
"${this.promise_dirname}${const.dirsep}input.txt",
"#[^\n]*",
" ",
"inf",
"inf"
);
"indices" slist => getindices( "input" );
reports:
"${with}" with => format( "%d", eval( "${input[${indices}][0]} + ${input[${indices}][1]}" ));
DEBUG::
"line_count is ${line_count}";
"input is ${with}" with => storejson( "input" );
"input[${indices}] is ${with}" with => storejson( "input[${indices}]" );
}
 
$ cat input.txt
2 3
2 2
 
$ cf-agent -KIf ./sum.cf
R: 5
R: 4
</syntaxhighlight>
 
The "R:" prefix is for a report promise and the only way to output to stdout with policy.
You could also output to a file I suppose.
 
=={{header|Clojure}}==
<syntaxhighlight lang="clojure">(println (+ (Integer/parseInt (read-line)) (Integer/parseInt (read-line))))
3
4
=>7</syntaxhighlight>
<syntaxhighlight lang="clojure">(eval (read-string (str "(+ " (read-line) " )") ))
3 3
6</syntaxhighlight>
 
Translation of Common Lisp version:
<syntaxhighlight lang="clojure">(println (+ (read) (read)))
3 4
7</syntaxhighlight>
Line 1,865 ⟶ 2,010:
 
Safely and without reader tricks:
<syntaxhighlight lang="clojure">(let [ints (map #(Integer/parseInt %) (clojure.string/split (read-line) #"\s") )]
(println (reduce + ints)))
3 4
Line 1,871 ⟶ 2,016:
 
or same as above, but without "let":
<syntaxhighlight lang="clojure">(println (reduce + (map #(Integer/parseInt %) (clojure.string/split (read-line) #"\s") )))
 
3 4
Line 1,877 ⟶ 2,022:
 
=={{header|COBOL}}==
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. A-Plus-B.
 
Line 1,900 ⟶ 2,045:
A second version.
 
<syntaxhighlight lang=COBOL"cobol">
 
IDENTIFICATION DIVISION.
Line 1,945 ⟶ 2,090:
=={{header|CoffeeScript}}==
{{trans|JavaScript}}
<syntaxhighlight lang="html4strict"><html>
<script type="text/javascript" src="http://jashkenas.github.com/coffee-script/extras/coffee-script.js"></script>
<script type="text/coffeescript">
Line 1,961 ⟶ 2,106:
 
{{works with|Node.js}}
<syntaxhighlight lang="coffeescript">
{ stdin } = process
sum = ( a, b ) -> a + b
Line 1,995 ⟶ 2,140:
 
=={{header|Common Lisp}}==
<syntaxhighlight lang="lisp">(write (+ (read) (read)))</syntaxhighlight>
 
=={{header|Component Pascal}}==
BlackBox Component Builder
<syntaxhighlight lang="oberon2">
MODULE AB;
IMPORT StdLog, DevCommanders,TextMappers;
Line 2,037 ⟶ 2,182:
 
=={{header|Computer/zero Assembly}}==
<syntaxhighlight lang="czasm"> STP ; wait for input
a: 0
b: 0
Line 2,045 ⟶ 2,190:
 
=={{header|Crystal}}==
<syntaxhighlight lang="ruby">puts gets.not_nil!.split.map(&.to_i).sum</syntaxhighlight>
 
The <code>not_nil!</code> call on <code>gets</code> is needed because <code>gets</code> might return <code>nil</code> and the compiler forces us to deal with it.
Line 2,052 ⟶ 2,197:
To handle the <code>nil</code> case we could do:
 
<syntaxhighlight lang="ruby">if line = gets
puts line.split.map(&.to_i).sum
else
Line 2,060 ⟶ 2,205:
=={{header|D}}==
===From Console===
<syntaxhighlight lang="d">import std.stdio, std.conv, std.string;
 
void main() {
Line 2,074 ⟶ 2,219:
<pre>30</pre>
===From File===
<syntaxhighlight lang="d">void main() {
import std.stdio, std.file;
 
Line 2,082 ⟶ 2,227:
 
=={{header|Dart}}==
<syntaxhighlight lang=Dart"dart">import 'dart:io';
 
// a little helper function that checks if the string only contains
Line 2,118 ⟶ 2,263:
 
=={{header|dc}}==
<syntaxhighlight lang="dc">? + psz</syntaxhighlight>
 
The question mark ''?'' reads and executes a line of input. The user must enter a dc program that pushes two numbers to the stack, such as ''2 3'' or ''5 _1''. (The user must use underscore ''_'' for negative numbers.)
 
=={{header|DCL}}==
<syntaxhighlight lang=DCL"dcl">$ read sys$command line
$ a = f$element( 0, " ", line )
$ b = f$element( 1, " ", line )
Line 2,130 ⟶ 2,275:
=={{header|Delphi}}==
Console version.
<syntaxhighlight lang="delphi">program SUM;
 
{$APPTYPE CONSOLE}
Line 2,147 ⟶ 2,292:
 
=={{header|Diego}}==
<syntaxhighlight lang="diego">set_namespace(rosettacode)_me();
begin_instuct(A + B);
Line 2,164 ⟶ 2,309:
 
=={{header|DMS}}==
<syntaxhighlight lang=DMS"dms">number a = GetNumber( "Please input 'a'", a, a ) // prompts for 'a'
number b = GetNumber( "Please input 'b'", b, b ) // prompts for 'b'
Result( a + b + "\n" )</syntaxhighlight>
 
=={{header|Dragon}}==
<syntaxhighlight lang="dragon">
select "graphic"
select "types"
Line 2,181 ⟶ 2,326:
=={{header|DWScript}}==
Ghetto GUI version
<syntaxhighlight lang="delphi">var a := StrToInt(InputBox('A+B', 'Enter 1st number', '0'));
var b := StrToInt(InputBox('A+B', 'Enter 2nd number', '0'));
ShowMessage('Sum is '+IntToStr(a+b));</syntaxhighlight>
Line 2,188 ⟶ 2,333:
{{trans|Python}}
===Console===
<syntaxhighlight lang="dejavu">0
for k in split !prompt "" " ":
+ to-num k
Line 2,194 ⟶ 2,339:
 
=={{header|EasyLang}}==
<syntaxhighlight>
<lang>a$ = input
a$ = input
while i < len a$ and substr a$ i 1 <> " "
repeat
i += 1
i += 1
until i > len a$ or substr a$ i 1 = " "
.
a = number substr a$ 01 i
b = number substr a$ i -199
print a + b
</syntaxhighlight>
 
=={{header|EchoLisp}}==
<syntaxhighlight lang="scheme">
(+ (read-number 1 "value for A") (read-number 2 "value for B"))
</syntaxhighlight>
Line 2,210 ⟶ 2,357:
=={{header|EDSAC order code}}==
The EDSAC does not support input of data while a program is running, so A and B are pre-set to 37 and 28. Other values can of course be substituted: note the slightly idiosyncratic format in which integer data is written (the least significant bit set using an alphabetic character). The result of the computation is displayed in binary in the first address of storage tank 3.
<syntaxhighlight lang="edsac">[ A plus B
========
Line 2,260 ⟶ 2,407:
 
3. Dismiss the message, make the file with the two integers the active file, and click Reset. The simulator will continue, read the integers, and print them together with their sum.
<syntaxhighlight lang="edsac">
[A + B for Rosetta Code.
Read two integers and find their sum.
Line 2,379 ⟶ 2,526:
=={{header|EGL}}==
 
<syntaxhighlight lang=EGL"egl">
package programs;
 
Line 2,402 ⟶ 2,549:
=={{header|Eiffel}}==
argument(0) contains the path of the executable - thus we start at argument(1)
<syntaxhighlight lang="eiffel">
class
APPLICATION
Line 2,419 ⟶ 2,566:
 
Alternatively ...
<syntaxhighlight lang="eiffel">
make
-- Run application.
Line 2,443 ⟶ 2,590:
 
=={{header|Ela}}==
<syntaxhighlight lang="ela">open monad io string list
 
a'b() = do
Line 2,456 ⟶ 2,603:
 
=={{header|Elena}}==
ELENA 56.0 :
<syntaxhighlight lang="elena">import extensions;
public program()
Line 2,468 ⟶ 2,615:
 
Or more generic solution:
<syntaxhighlight lang="elena">import system'routines;
import extensions;
 
Line 2,475 ⟶ 2,622:
console.printLine(console.readLine()
.split()
.selectBy(mssgconst toInt<convertorOpintConvertOp>[1])
.summarize())
}</syntaxhighlight>
 
=={{header|Elixir}}==
<syntaxhighlight lang=Elixir"elixir">IO.gets("Enter two numbers seperated by a space: ")
|> String.split
|> Enum.map(&String.to_integer(&1))
Line 2,487 ⟶ 2,634:
 
=={{header|Elm}}==
<syntaxhighlight lang=Elm"elm">
--To write this function directly run cmd
--Type elm-repl to start
Line 2,502 ⟶ 2,649:
 
=={{header|Emacs Lisp}}==
<syntaxhighlight lang="lisp">(let* ((input (read-from-minibuffer ""))
(numbers (mapcar #'string-to-number (split-string input)))
(a (car numbers))
(b (cadr numbers)))
(message "%d" (+ a b)))</syntaxhighlight>
 
=={{header|EMal}}==
<syntaxhighlight lang="emal">
fun main = int by List args
text input = when(args.length == 1, args[0], ask(text, "Enter n integers separated by a space: "))
int sum, count
for each text word in input.split(" ")
word = word.trim()
if word.isEmpty() do continue end # ignore empty words
int nr = int!word # this can raise an exception
if abs(nr) > 1000
Event.error(0, "Integers must be in the interval [-1000, 1000]").raise()
end
sum += nr
++count
end
if count < 2 do Event.error(1, "At least two integers must be provided").raise() end
writeLine("The sum of " + count + " integers is: " + sum)
return 0
end
exit main(Runtime.args)
</syntaxhighlight>
{{out}}
<pre>
emal.exe Org\RosettaCode\Aplusb.emal " 9 8 "
The sum of 2 integers is: 17
</pre>
 
=={{header|Emojicode}}==
<syntaxhighlight lang=Emojicode"emojicode">🏁🍇
🆕🔡▶️👂🏼❗️ ➡️ input 💭 Get numbers as input string
🔫 input 🔤 🔤❗ ➡️ nums 💭 Split numbers by space
Line 2,518 ⟶ 2,692:
 
=={{header|Erlang}}==
<syntaxhighlight lang="erlang">-module(aplusb).
-export([start/0]).
 
Line 2,530 ⟶ 2,704:
 
=={{header|ERRE}}==
<syntaxhighlight lang=ERRE"erre">
PROGRAM SUM2
 
Line 2,544 ⟶ 2,718:
END PROGRAM
</syntaxhighlight>
 
=={{header|Euler}}==
'''begin'''
'''out''' '''in''' + '''in'''
'''end''' $
 
=={{header|Euler Math Toolbox}}==
 
<syntaxhighlight lang=Euler"euler Mathmath Toolboxtoolbox">
>s=lineinput("Two numbers seperated by a blank");
Two numbers seperated by a blank? >4 5
Line 2,558 ⟶ 2,737:
 
=={{header|Euphoria}}==
<syntaxhighlight lang="euphoria">include get.e
 
function snd(sequence s)
Line 2,574 ⟶ 2,753:
Take any 3 columns of any row or rows. Let's say A1,B1 and C1 are taken. In C1 type in :
 
<syntaxhighlight lang="excel">
=A1+B1
</syntaxhighlight>
Line 2,580 ⟶ 2,759:
The value of C1 will change as the values of A1 and B1 are changed
 
<syntaxhighlight lang="text">1 2 3
</syntaxhighlight>
 
=={{header|F Sharp|F#}}==
<syntaxhighlight lang="fsharp">open System
 
let SumOf(str : string) =
Line 2,595 ⟶ 2,774:
 
=={{header|Factor}}==
<syntaxhighlight lang="factor">USING: math.parser splitting ;
: a+b ( -- )
readln " " split1
Line 2,607 ⟶ 2,786:
 
=={{header|FALSE}}==
<syntaxhighlight lang="false">[0[^$$'9>'0@>|~]['0-\10*+]#%]n: {read an integer}
n;!n;!+.</syntaxhighlight>
 
=={{header|Fantom}}==
<syntaxhighlight lang="fantom">class APlusB
{
public static Void main ()
Line 2,625 ⟶ 2,804:
=={{header|FBSL}}==
Using stdin and stdout
<syntaxhighlight lang="qbasic">#APPTYPE CONSOLE
 
DIM %a, %b
Line 2,632 ⟶ 2,811:
 
PAUSE</syntaxhighlight>
 
=={{header|Fennel}}==
{{trans|Lua}}
<syntaxhighlight lang="fennel">
(let [(a b) (io.read :*number :*number)]
(print (+ a b)))
</syntaxhighlight>
 
=={{header|Fhidwfe}}==
<syntaxhighlight lang=Fhidwfe"fhidwfe">
function listint scanint (num:ptr) {// as of writing, fhidwfe has no builtin int scanning
reset negative
Line 2,679 ⟶ 2,865:
 
=={{header|Fish}}==
<syntaxhighlight lang=Fish"fish">i:o:"-"=?v1$68*-v
v >~01-0 >
>i:o:" "=?v68*-$a*+
Line 2,688 ⟶ 2,874:
 
=={{header|Forth}}==
<syntaxhighlight lang=Forth"forth">pad dup 80 accept evaluate + .</syntaxhighlight>
 
=={{header|Fortran}}==
<syntaxhighlight lang="fortran">program a_plus_b
implicit none
integer :: a,b
Line 2,698 ⟶ 2,884:
end program a_plus_b</syntaxhighlight>
And in Fortran 77
<syntaxhighlight lang="fortran"> READ (1,100) I,J
100 FORMAT(2I5)
WRITE (2,200) I+J
Line 2,705 ⟶ 2,891:
 
=={{header|Free Pascal}}==
<syntaxhighlight lang="pascal">program SUMA;
uses
SysUtils;
Line 2,720 ⟶ 2,906:
=={{header|Frink}}==
This program handles arbitrarily-large integers, or even floating-point or rational numbers or complex numbers (as long as they're not internally separated with spaces, of course, which are the delimiters for this task.) It can even handle units of measure (with no embedded spaces) such as "3.3meter 2feet" and does the right thing when summing those units. It can handle any number of arbitrary whitespace characters separating the numbers. It also works whether the input is user-interactive, or input comes from stdin or a pipe. (It will bring up a user dialog for input when run in a graphical environment.)
<syntaxhighlight lang="frink">
sum[eval[split[%r/\s+/, input[""]]]]
</syntaxhighlight>
 
=={{header|FunL}}==
<syntaxhighlight lang="funl">println( sum(map(int, readLine().split(' +'))) )</syntaxhighlight>
 
=={{header|Furor}}==
<syntaxhighlight lang=Furor"furor">
cin sto mystring
#s dec mystring @mystring sprintnl
Line 2,775 ⟶ 2,961:
=={{header|FutureBasic}}==
The input statement was removed from FB several years ago. However, it's trivial to write our own input field which compiles as a stand-alone Macintosh application.
<syntaxhighlight lang="futurebasic">
_window = 1
begin enum 1
Line 2,829 ⟶ 3,015:
 
=={{header|Gambas}}==
<syntaxhighlight lang="gambas">Public Sub Main()
Dim sInput As String = InputBox("Input 2 numbers seperated by a space", "A + B")
 
Line 2,842 ⟶ 3,028:
=={{header|Gastona}}==
Taking A and B from command line arguments
<syntaxhighlight lang="gastona">#listix#
 
<main>
Line 2,849 ⟶ 3,035:
</syntaxhighlight>
Using Graphical interface
<syntaxhighlight lang="gastona">#javaj#
 
<layout of main>
Line 2,864 ⟶ 3,050:
<suma> =, eA + eB
</syntaxhighlight>
 
=={{header|GDScript}}==
Requires Godot 4. Runs as a tool script using the input and output properties. Does not check for zero lines of input.
 
<syntaxhighlight lang="gdscript">
@tool
extends Node
 
@export var input: String:
set(value):
input = value # Save the input field
 
var fields := value.split(" ", false) # Split by spaces
if len(fields) == 2: # Basic input validation
output = str(int(fields[0]) + int(fields[1]))
else: # Invalid input
output = ""
 
@export var output: String
</syntaxhighlight>
 
=={{header|Gema}}==
<syntaxhighlight lang="gema"><D> <D>=@add{$1;$2}</syntaxhighlight>
 
=={{header|Genie}}==
<syntaxhighlight lang="genie">[indent=4]
/*
A+B in Genie
Line 2,912 ⟶ 3,118:
 
=={{header|GML}}==
<syntaxhighlight lang=GML"gml">var add, a, b;
add = argument0; // get the string with the numbers to add
a = real(string_copy(add, 1, string_pos(" ", add)));
Line 2,919 ⟶ 3,125:
 
=={{header|Go}}==
<syntaxhighlight lang="go">package main
 
import "fmt"
Line 2,930 ⟶ 3,136:
 
=={{header|Golfscript}}==
<syntaxhighlight lang="golfscript">~+</syntaxhighlight>
 
=={{header|Golo}}==
<syntaxhighlight lang=Golo"golo">#!/usr/bin/env golosh
----
This module asks for two numbers, adds them, and prints the result.
Line 2,962 ⟶ 3,168:
 
=={{header|Gosu}}==
<syntaxhighlight lang=Gosu"gosu">
uses java.io.InputStreamReader
uses java.util.Scanner
Line 2,975 ⟶ 3,181:
 
=={{header|Groovy}}==
<syntaxhighlight lang="groovy">def abAdder = {
def reader = new Scanner(System.in)
def a = reader.nextInt();
Line 2,986 ⟶ 3,192:
=={{header|GUISS}}==
We cannot use variables, but we can find the sum of two numbers.Here we add 3 + 2:
<syntaxhighlight lang="guiss">Start,Programs,Accessories,Calculator,Button:3,Button:[plus],
Button:2,Button:[equals]</syntaxhighlight>
 
=={{header|Harbour}}==
<syntaxhighlight lang="visualfoxpro">PROCEDURE Main()
LOCAL GetList := {}
LOCAL bValid := { |n| iif(n>-1001, iif(n<1001, .T.,.F.),.F.) }
Line 3,009 ⟶ 3,215:
 
=={{header|Haskell}}==
<syntaxhighlight lang="haskell">main = print . sum . map read . words =<< getLine</syntaxhighlight>
 
=={{header|hexiscript}}==
<syntaxhighlight lang="hexiscript">fun split s delim
let ret dict 32
let l len s
Line 3,036 ⟶ 3,242:
=={{header|HicEst}}==
A and B are input via edit controls with spinners limiting inputs to +-1000.
<syntaxhighlight lang=HicEst"hicest">DLG(Edit=A, DNum, MIn=-1000, MAx=1000, E=B, DN, MI=-1000, MA=1000)
WRITE(Messagebox, Name) A, B, "Sum = ", A+B</syntaxhighlight>
 
=={{header|Hoon}}==
<syntaxhighlight lang="text">
|= [a=@ud b=@ud] (add a b)
</syntaxhighlight>
Line 3,060 ⟶ 3,266:
 
=={{header|Huginn}}==
<syntaxhighlight lang="huginn">import Algorithms as algo;
import Text as text;
 
Line 3,078 ⟶ 3,284:
 
=={{header|Hy}}==
<syntaxhighlight lang="hy">(print (sum (map int (.split (input)))))</syntaxhighlight>
Alternatively, with the "threading tail" macro:
<syntaxhighlight lang="hy">(->> (input) (.split) (map int) (sum) (print))</syntaxhighlight>
 
=={{header|i}}==
<syntaxhighlight lang="i">main: print(integer(in(' '))+integer(in('\n'))); ignore</syntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
<syntaxhighlight lang="icon">procedure main()
numChars := '-'++&digits
read() ? {
Line 3,096 ⟶ 3,302:
 
=={{header|Idris}}==
<syntaxhighlight lang="idris">main : IO()
main = do
line <- getLine
print $ sum $ map cast $ words line</syntaxhighlight>
 
=={{header|Insitux}}==
<syntaxhighlight lang="insitux">(+ (to-num (prompt "Enter first number: "))
(to-num (prompt "Enter second number: ")))</syntaxhighlight>
 
=={{header|J}}==
Typically, in J, you would find the sum of two numbers (let us say 2 and 3) by entering both of them on a line with a + sign between them:
<syntaxhighlight lang=J"j"> 2+3
5</syntaxhighlight>
Next we describe then implement a command line program to add some numbers.
 
1) In the following expression, <tt>1!:1(3)</tt> reads a line from STDIN; <tt>-.LF</tt> drops the line ending character; <tt>".</tt> converts the remaining text to a sequence of numbers which are then summed using <tt>+/</tt>.
<syntaxhighlight lang=J"j">+/". (1!:1(3))-.LF</syntaxhighlight>
2) Here's a little script, called "a+b.ijs":
<syntaxhighlight lang=J"j">#!/Applications/j602usr/bin/jconsoleijconsole
echo +/". (1!:1(3))-.LF
exit ''</syntaxhighlight>
3) Here is an execution of the script:
<syntaxhighlight lang="bash">echo 2 3 | ./a+b.ijs
5</syntaxhighlight>
 
Note: under OSX, you should probably install a symbolic link at /usr/bin/ijconsole which links to something like /Applications/j602/bin/jconsole.
 
=={{header|Java}}==
The task description is somewhat vague, if the 'input stream' is in reference to the data provided at the command line, then Java will parse these values into a <code>String</code> array, accessible via the <kbd>args</kbd> parameter of the <code>main</code> method.
<syntaxhighlight lang=java>import java.util.Scanner;
<syntaxhighlight lang="java">
public static void main(String[] args) {
int A = Integer.parseInt(args[0]);
int B = Integer.parseInt(args[1]);
System.out.println(A + B);
}
</syntaxhighlight>
If the 'input stream' is the standard-in, you can use the following.<br />
The <code>Scanner</code> class can be used to "scan" the standard-in stream from left to right, returning the next value requested.
<syntaxhighlight lang="java">
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int A = scanner.nextInt();
int B = scanner.nextInt();
System.out.println(A + B);
}
</syntaxhighlight>
If the 'input stream' is referring to any abstraction, then you can use the following.<br />
In this example, the data is considered to be under a specific charset, so the integer values are parsed using UTF-8.
<syntaxhighlight lang="java">
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
</syntaxhighlight>
<syntaxhighlight lang="java">
int sum(InputStream input) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
String line = reader.readLine();
reader.close();
/* split parameter here is a regex */
String[] values = line.split(" +");
int A = Integer.parseInt(values[0]);
int B = Integer.parseInt(values[1]);
return A + B;
}
</syntaxhighlight>
<br />
An alternate implemenation
<syntaxhighlight lang="java">import java.util.Scanner;
 
public class Sum2 {
Line 3,127 ⟶ 3,382:
}</syntaxhighlight>
Object of [[class]] Scanner works slow enough, because of that contestants prefer to avoid its use. Often, longer solution works faster and easily scales to problems.
<syntaxhighlight lang="java">import java.io.*;
import java.util.*;
 
Line 3,157 ⟶ 3,412:
The following code uses a StreamTokenizer instead of a Scanner.
 
<syntaxhighlight lang="java">import java.io.*;
import java.nio.charset.Charset;
 
Line 3,176 ⟶ 3,431:
 
 
<syntaxhighlight lang="text">
grammar aplusb ;
 
Line 3,212 ⟶ 3,467:
Client side:
 
<syntaxhighlight lang="html4strict"><html>
<body>
<div id='input'></div>
Line 3,229 ⟶ 3,484:
Server side (with [http://nodejs.org node.js]):
 
<syntaxhighlight lang="javascript">process.openStdin().on (
'data',
function (line) {
Line 3,249 ⟶ 3,504:
=== ES6 ===
Node.js in a terminal:
<syntaxhighlight lang="javascript">process.stdin.on("data", buffer => {
console.log(
(buffer + "").trim().split(" ").map(Number).reduce((a, v) => a + v, 0)
Line 3,262 ⟶ 3,517:
 
=== JScript Windows Script Host Version 5.8 ===
<syntaxhighlight lang="javascript">var a = WScript.StdIn.ReadLine();
var b = WScript.StdIn.ReadLine();
WSH.echo(a, " + " , b , " = " , Number(a)+Number(b));
Line 3,269 ⟶ 3,524:
=={{header|Joy}}==
===Console===
<syntaxhighlight lang=Joy"joy">get get +.</syntaxhighlight>
===File===
<syntaxhighlight lang=Joy"joy">"input.txt" include
"output.txt" "w" fopen
get get + fput pop quit.</syntaxhighlight>
Line 3,277 ⟶ 3,532:
=={{header|jq}}==
Since the given task is simply to add two numbers, the simplest approach in jq is illustrated by the following transcript:
<syntaxhighlight lang="jq">$ jq -s add
3 2
5 </syntaxhighlight>
This will work provided the numbers are neither too small nor too large. However, the above program will add **all** the numbers presented on the stream (assuming only numbers are presented). If the task were to add consecutive pairs of numbers, then the approach illustrated in the following transcript can be used, in conjunction with the jq "-s" option:<syntaxhighlight lang="jq">
def addpairs:
if length < 2 then empty
Line 3,287 ⟶ 3,542:
 
addpairs</syntaxhighlight>
For example, here is a transcript that assumes the program is in a file named AB.jq:<syntaxhighlight lang="jq">
$ jq -s -f AB.jq
1 2 3 4 5 6
Line 3,295 ⟶ 3,550:
 
=={{header|Jsish}}==
<syntaxhighlight lang="javascript">/* A+B in Jsish */
var line = console.input();
var nums = line.match(/^\s*([+-]?[0-9]+)\s+([+-]?[0-9]+)\s*/);
Line 3,326 ⟶ 3,581:
=={{header|Julia}}==
Run from the command line:
<syntaxhighlight lang="julia">input = parse.(Int, split(readline(stdin)))
println(stdout, sum(input))</syntaxhighlight>
 
Line 3,335 ⟶ 3,590:
 
In the next solution, an error is returned if the entry is not constituted from exactly two integers. Any number of spaces can follow an integer.
<syntaxhighlight lang=Julia"julia">julia> println(parse(Int, readuntil(stdin, ' ')) + parse(Int, readuntil(stdin, '\n')))
1 2
3</syntaxhighlight>
 
=={{header|K}}==
<syntaxhighlight lang=K"k">
split:{(a@&~&/' y=/: a:(0,&x=y)_ x) _dv\: y}
ab:{+/0$split[0:`;" "]}
Line 3,349 ⟶ 3,604:
 
=={{header|Keg}}==
<syntaxhighlight lang=Keg"keg">+.</syntaxhighlight>
[https://tio.run/##y05N//9fW@//f1MDLjMDAA Try it online!]
 
Or, using flags (<code>-hr</code>):
<syntaxhighlight lang=Keg"keg">+</syntaxhighlight>
[https://tio.run/##y05N//9f@/9/UwMuM4P/uhlFAA Try it online!]
 
=={{header|Kite}}==
<syntaxhighlight lang=Kite"kite">#!/usr/bin/kite
 
import "System.file";
Line 3,379 ⟶ 3,634:
 
=={{header|Klong}}==
<syntaxhighlight lang=K"k">
{(1:$(*x?0c )#x)+1:$(1+*|x?0c )_x}@.rl()
2 3
Line 3,386 ⟶ 3,641:
 
=={{header|Kotlin}}==
<syntaxhighlight lang="scala">// version 1.0.5-2
 
fun main(args: Array<String>) {
Line 3,422 ⟶ 3,677:
 
=={{header|KQL}}==
<syntaxhighlight lang=KQL"kql">datatable(Input:string)[
'2 2',
'3 2'
Line 3,430 ⟶ 3,685:
 
=={{header|L++}}==
<syntaxhighlight lang="lisp">(main
(decl int a)
(decl int b)
Line 3,437 ⟶ 3,692:
 
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
Lambdatalk works in a wiki, lambdatank.
 
Line 3,469 ⟶ 3,724:
Several boxes can be created in the wiki page
with any valid lambdatalk expressions.
</syntaxhighlight>
 
=={{header|Lang}}==
<syntaxhighlight lang="lang">
fn.print(First number:\s)
$a = fn.int(fn.input())
 
fn.print(Second number:\s)
$b = fn.int(fn.input())
 
fn.println(Result: parser.op($a + $b))
</syntaxhighlight>
 
=={{header|Lang5}}==
<syntaxhighlight lang="lang5">read read + .
 
read " " split expand drop + .</syntaxhighlight>
 
=={{header|Lasso}}==
<syntaxhighlight lang="lb">[a + b]</syntaxhighlight>
 
=={{header|LIL}}==
<syntaxhighlight lang="tcl"># A+B, in LIL
# Requires lil shell readline routine
set in [readline]
Line 3,494 ⟶ 3,760:
 
=={{header|Lisaac}}==
<syntaxhighlight lang="lisaac">Section Header
+ name := A_PLUS_B
 
Line 3,502 ⟶ 3,768:
 
=={{header|Little}}==
<syntaxhighlight lang="c">void main() {
string a, b;
scan(gets(stdin), "%d %d", &a, &b);
Line 3,514 ⟶ 3,780:
 
'''Assembly'''
<syntaxhighlight lang=Little"little Manman Computercomputer"> INP
STA 99
INP
Line 3,523 ⟶ 3,789:
 
'''Machine code'''
<syntaxhighlight lang=Little"little Manman Computercomputer">00 INP
01 STA 99
02 INP
Line 3,532 ⟶ 3,798:
=={{header|LiveCode}}==
Using Livecode Server script
<syntaxhighlight lang=LiveCode"livecode"><?lc
if isNumber($0) and isNumber($1) then
put $0 + $1
Line 3,541 ⟶ 3,807:
 
A graphical version using an input dialog
<syntaxhighlight lang=LiveCode"livecode">on mouseUp
ask "Enter two numbers"
set itemdelimiter to space
Line 3,553 ⟶ 3,819:
 
=={{header|Logo}}==
<syntaxhighlight lang="logo">show apply "sum readlist</syntaxhighlight>
 
=={{header|Lua}}==
<syntaxhighlight lang=Lua"lua">a,b = io.read("*number", "*number")
print(a+b)</syntaxhighlight>
 
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="text">Def Range(X%)=Abs(X%)<=1000
Do {
Input A%, B%
Line 3,567 ⟶ 3,833:
 
=={{header|M4}}==
<syntaxhighlight lang=M4"m4"> define(`sumstr', `eval(patsubst(`$1',` ',`+'))')
 
sumstr(1 2)
Line 3,573 ⟶ 3,839:
 
=={{header|Maple}}==
<syntaxhighlight lang="maple"> convert( scanf( "%d %d" ), '`+`' );
23 34
57</syntaxhighlight>
Line 3,579 ⟶ 3,845:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
Interactive in a notebook
<syntaxhighlight lang=Mathematica"mathematica">Input[] + Input[]</syntaxhighlight>
 
=={{header|MATLAB}} / {{header|Octave}}==
<syntaxhighlight lang=MATLAB"matlab">function sumOfInputs = APlusB()
inputStream = input('Enter two numbers, separated by a space: ', 's');
numbers = str2num(inputStream); %#ok<ST2NM>
Line 3,593 ⟶ 3,859:
=={{header|Maude}}==
===Built-in===
<syntaxhighlight lang=Maude"maude">
red 3 + 4 .
</syntaxhighlight>
===With restrictions===
<syntaxhighlight lang=Maude"maude">
fmod ADD is
 
Line 3,613 ⟶ 3,879:
 
=={{header|Maxima}}==
<syntaxhighlight lang="text">in_stream: openr("/dev/stdin");
unless (line: readline(in_stream), line=false) do (
q: map('parse_string, split(line, " ")),
Line 3,622 ⟶ 3,888:
 
=={{header|Mercury}}==
<syntaxhighlight lang="text">:- module a_plus_b.
:- interface.
 
Line 3,645 ⟶ 3,911:
=={{header|min}}==
{{works with|min|0.19.3}}
<syntaxhighlight lang="min">gets " " split 'bool filter 'int map sum puts!</syntaxhighlight>
 
=={{header|MiniScript}}==
The <code>input</code> intrinsic in MiniScript isn't available in all implementations, so we've just hard-coded the input here:
<syntaxhighlight lang=MiniScript"miniscript">s = " 2 3 "
fields = s.split
for i in range(fields.len-1, 0)
Line 3,664 ⟶ 3,930:
 
=={{header|mIRC Scripting Language}}==
<syntaxhighlight lang="mirc">alias a+b {
echo -ag $calc($1 + $2)
}</syntaxhighlight>
Line 3,675 ⟶ 3,941:
=={{header|ML/I}}==
The two numbers are read from 'standard input' or its equivalent.
<syntaxhighlight lang=ML"ml/Ii">MCSKIP "WITH" NL
"" A+B
"" assumes macros on input stream 1, terminal on stream 2
Line 3,690 ⟶ 3,956:
 
=={{header|Modula-2}}==
<syntaxhighlight lang="modula2">MODULE ab;
 
IMPORT InOut;
Line 3,704 ⟶ 3,970:
 
=={{header|Modula-3}}==
<syntaxhighlight lang="modula3">MODULE Ab EXPORTS Main;
 
IMPORT IO;
Line 3,722 ⟶ 3,988:
 
=={{header|MoonScript}}==
<syntaxhighlight lang="moonscript">a,b = io.read '*number','*number'
print a + b</syntaxhighlight>
 
=={{header|Mosaic}}==
<syntaxhighlight lang="mosaic">
proc main =
int a, b
 
print "?"
readln a, b
println a + b
end
</syntaxhighlight>
 
=={{header|MUMPS}}==
<syntaxhighlight lang=MUMPS"mumps">ANB
NEW A,B,T,S
READ !,"Input two integers between -1000 and 1000, separated by a space: ",S
Line 3,736 ⟶ 4,013:
 
=={{header|Nanoquery}}==
<syntaxhighlight lang=Nanoquery"nanoquery">// get a line of input
line = input()
Line 3,746 ⟶ 4,023:
 
=={{header|Neko}}==
<syntaxhighlight lang=ActionScript"actionscript">/**
A+B, Rosetta Code, in Neko
Tectonics:
Line 3,822 ⟶ 4,099:
=={{header|Nemerle}}==
{{trans|C#}}
<syntaxhighlight lang=Nemerle"nemerle">using System;
using System.Console;
using System.Linq;
Line 3,835 ⟶ 4,112:
 
=={{header|NetRexx}}==
<syntaxhighlight lang=NetRexx"netrexx">/* NetRexx */
 
options replace format comments java symbols binary
Line 3,843 ⟶ 4,120:
 
=={{header|newLISP}}==
<syntaxhighlight lang=newLISP"newlisp">(println (apply + (map int (parse (read-line)))))</syntaxhighlight>
 
=={{header|Nim}}==
A+B:
<syntaxhighlight lang="nim">
# Takes 2 inputs of Floats and adds them (which is not correct for the exercise, will revisit, Thank you
 
Line 3,875 ⟶ 4,152:
=={{header|Nit}}==
Generic non-robust version (source: [https://github.com/nitlang/nit/blob/master/examples/rosettacode/ab.nit the Nit’s official repository]):
<syntaxhighlight lang="nit">module ab
 
var words = gets.split(" ")
Line 3,885 ⟶ 4,162:
 
=={{header|NS-HUBASIC}}==
<syntaxhighlight lang=NS"ns-HUBASIChubasic">10 INPUT "ENTER NUMBER A: ",A
20 INPUT "ENTER NUMBER B: ",B
30 PRINT A+B</syntaxhighlight>
 
=={{header|Nu}}==
<syntaxhighlight lang="nu">
input | parse "{a} {b}" | first | values | into int | math sum
</syntaxhighlight>
 
=={{header|Nutt}}==
<syntaxhighlight lang="Nutt">
module main
imports native.io{input.hear,output.say}
 
vals a=hear(Int),b=hear(Int)
say(a+b)
 
end
</syntaxhighlight>
 
=={{header|Nyquist}}==
===SAL Syntax===
<syntaxhighlight lang=Nyquist"nyquist">;nyquist plug-in
;version 1
;type tool
Line 3,905 ⟶ 4,198:
 
===Audacity plug-in (SAL syntax)===
<syntaxhighlight lang=Nyquist"nyquist">;nyquist plug-in
;version 1
;type tool
Line 3,919 ⟶ 4,212:
 
=={{header|Oberon-2}}==
<syntaxhighlight lang="oberon2">MODULE ab;
 
IMPORT In, Out;
Line 3,938 ⟶ 4,231:
 
=={{header|Objeck}}==
<syntaxhighlight lang="objeck">bundle Default {
class Vander {
function : Main(args : String[]) ~ Nil {
Line 3,950 ⟶ 4,243:
 
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">Scanf.scanf "%d %d" (fun a b -> Printf.printf "%d\n" (a + b))</syntaxhighlight>
 
=={{header|Oforth}}==
Line 3,956 ⟶ 4,249:
Works with any number of integers separated by a space.
 
<syntaxhighlight lang=Oforth"oforth">import: mapping
 
System.Console accept words map( #>integer) reduce( #+ ) printcr .</syntaxhighlight>
Line 3,963 ⟶ 4,256:
Note: input data must be separated by newline ([Enter] key press).
 
<syntaxhighlight lang="ol">; simplest
(+ (read) (read))
 
Line 3,979 ⟶ 4,272:
=={{header|Onyx}}==
 
<syntaxhighlight lang="onyx">$Prompt {
`\nEnter two numbers between -1000 and +1000,\nseparated by a space: ' print flush
} def
Line 4,008 ⟶ 4,301:
===version 1===
{{trans|REXX}}
<syntaxhighlight lang="oorexx">Numeric digits 1000 /*just in case the user gets ka-razy. */
Say 'enter some numbers to be summed:'
parse pull y
Line 4,032 ⟶ 4,325:
===version 2===
extend for negative numbers
<syntaxhighlight lang="oorexx">Numeric digits 1000
Say 'enter some numbers to be summed:'
parse pull y
Line 4,055 ⟶ 4,348:
 
=={{header|OpenEdge/Progress}}==
<syntaxhighlight lang="progress">DEFINE VARIABLE a AS INTEGER NO-UNDO FORMAT "->>>9".
DEFINE VARIABLE b AS INTEGER NO-UNDO FORMAT "->>>9".
 
Line 4,070 ⟶ 4,363:
=={{header|Openscad}}==
There is no means of run-time input in Openscad
<syntaxhighlight lang="openscad">
a = 5 + 4;
echo (a);
Line 4,079 ⟶ 4,372:
 
To run this Order program, you must define the macros '''A''' and '''B''' to values of the form '''8int(SIGN, 8nat(VALUE))''', where SIGN is 1/0 to represent signed/unsigned numbers, and VALUES is any comma-separated list of decimal digits. For example, to evaluate the sum of A=-150, B=275, define A to be '''8int(1, 8nat(1,5,0))''' and B to be '''8int(0, 8nat(2,7,5))'''.
<syntaxhighlight lang="order">
#define ORDER_PP_DEF_1int_is_positive \
ORDER_PP_FN(8fn(8X, 8is_0(8tuple_at_0(8X))))
Line 4,119 ⟶ 4,412:
 
=={{header|Oxygene}}==
<syntaxhighlight lang="oxygene">
// Sum 2 integers read fron standard input
//
Line 4,161 ⟶ 4,454:
 
=={{header|Oz}}==
<syntaxhighlight lang="oz">declare
class TextFile from Open.file Open.text end
 
Line 4,174 ⟶ 4,467:
=={{header|PARI/GP}}==
User input:
<syntaxhighlight lang="parigp">input()+input()</syntaxhighlight>
File input:
<syntaxhighlight lang="parigp">read("file1")+read("file2")</syntaxhighlight>
 
=={{header|Pascal}}==
<syntaxhighlight lang="pascal">var
a, b: integer;
begin
Line 4,186 ⟶ 4,479:
end.</syntaxhighlight>
Same with input from file <tt>input.txt</tt> and output from file <tt>output.txt</tt>.
<syntaxhighlight lang="pascal">var
a, b: integer;
begin
Line 4,197 ⟶ 4,490:
end.</syntaxhighlight>
===Version 2. Following the rules===
<syntaxhighlight lang="pascal">{ Task: A + B
Sum of A + B while A, B >= -1000 and A,B <= 1000
Author: Sinuhe Masan (2019) }
Line 4,217 ⟶ 4,510:
 
=={{header|Perl}}==
<syntaxhighlight lang=Perl"perl">my ($a,$b) = split(' ', scalar(<STDIN>));
print "$a $b " . ($a + $b) . "\n";</syntaxhighlight>
 
=== using the List::Util module ===
<syntaxhighlight lang=Perl"perl">say sum split /\s+/, scalar <STDIN>;</syntaxhighlight>
 
=={{header|Phix}}==
<!--<syntaxhighlight lang=Phix"phix">-->
<span style="color: #000080;font-style:italic;">-- demo\rosetta\AplusB.exw</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">prompt_string</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"Enter two numbers separated by a space : "</span><span style="color: #0000FF;">)</span>
Line 4,241 ⟶ 4,534:
</pre>
=== GUI version ===
{{libheader|Phix/pGUI}}
<small>(The above console version is now just a comment in the distributed file.)</small>
<!--<syntaxhighlight lang=Phix"phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">-- demo\rosetta\AplusB.exw</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
Line 4,278 ⟶ 4,572:
 
=={{header|Phixmonti}}==
<syntaxhighlight lang=Phixmonti"phixmonti">/# Rosetta Code problem: http://rosettacode.org/wiki/A+B
by Galileo, 05/2022 #/
 
Line 4,294 ⟶ 4,588:
 
over over + >ps
nl "The sum of " print print " and " print print " is: " print ps> print</syntaxhighlight>
/#
swap over over + >ps >ps >ps
nl ( "The sum of " ps> " and " ps> " is: " ps> ) lprint
#/</syntaxhighlight>
{{out}}
<pre>Enter two numbers (betwen -1000 ... +1000) separated by space: 2 3
Line 4,301 ⟶ 4,599:
 
=={{header|PHP}}==
<syntaxhighlight lang="php">fscanf(STDIN, "%d %d\n", $a, $b); //Reads 2 numbers from STDIN
echo ($a + $b) . "\n";</syntaxhighlight>
<syntaxhighlight lang="php">$in = fopen("input.dat", "r");
fscanf($in, "%d %d\n", $a, $b); //Reads 2 numbers from file $in
fclose($in);
Line 4,312 ⟶ 4,610:
 
=={{header|Picat}}==
<syntaxhighlight lang=Picat"picat">
go =>
println("Write two integers (and CR)"),
Line 4,333 ⟶ 4,631:
 
=={{header|PicoLisp}}==
<syntaxhighlight lang=PicoLisp"picolisp">(+ (read) (read))
3 4
-> 7</syntaxhighlight>
Line 4,340 ⟶ 4,638:
[[File:Piet A+B.png]]
The code is fairly straightforward. The individual commands are as follows:
<syntaxhighlight lang="text">in(num)
in(num)
add
Line 4,346 ⟶ 4,644:
 
=={{header|Pike}}==
<syntaxhighlight lang=Pike"pike">string line = Stdio.stdin->gets();
sscanf(line, "%d %d", int a, int b);
write(a+b +"\n");</syntaxhighlight>
 
=={{header|PL/I}}==
<syntaxhighlight lang="pli">get (a, b);
put (a+b);</syntaxhighlight>
 
=={{header|Plain English}}==
<syntaxhighlight lang="plainenglish">
To run:
Start up.
Read a number from the console.
Read another number from the console.
Output the sum of the number and the other number.
Wait for the escape key.
Shut down.
 
To output the sum of a number and another number:
If the number is not valid, write "Invalid input" to the console; exit.
If the other number is not valid, write "Invalid input" to the console; exit.
Write the number plus the other number then " is the sum." to the console.
 
To decide if a number is valid:
If the number is not greater than or equal to -1000, say no.
If the number is not less than or equal to 1000, say no.
Say yes.
</syntaxhighlight>
 
=={{header|Pony}}==
<syntaxhighlight lang="pony">
actor Main
let _env:Env
Line 4,384 ⟶ 4,703:
 
=={{header|PostScript}}==
<syntaxhighlight lang="postscript">(%stdin) (r) file % get stdin
dup
token pop % read A
Line 4,393 ⟶ 4,712:
 
=={{header|Potion}}==
<syntaxhighlight lang="potion"># The numbers are entered, piped, or redirected in via STDIN and the format is proper (i.e., "%d %d").
input = read
i = 0
Line 4,408 ⟶ 4,727:
 
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">$a,$b = -split "$input"
[int]$a + [int]$b</syntaxhighlight>
This solution does not work interactively, while the following ''only'' works interactively:
<syntaxhighlight lang="powershell">$a,$b = -split (Read-Host)
[int]$a + [int]$b</syntaxhighlight>
 
I think this works better and doesn't require string input (following the task closer):
<syntaxhighlight lang="powershell">filter add {
return [int]$args[0] + [int]$args[1]
}</syntaxhighlight>
 
Can be called in one line with
<syntaxhighlight lang="powershell">add 2 3</syntaxhighlight>
 
=={{header|Processing}}==
===Rudimentary User Interface===
Click on either side to add 1 to its value.
<syntaxhighlight lang=Processing"processing">int a = 0;
int b = 0;
 
Line 4,455 ⟶ 4,774:
=={{header|ProDOS}}==
With the math module:
<syntaxhighlight lang=ProDOS"prodos">editvar /newvar /value=a /title=Enter an integer:
editvar /newvar /value=b /title=Enter another integer:
editvar /newvar /value=c
Line 4,461 ⟶ 4,780:
printline -c- </syntaxhighlight>
Without the math module:
<syntaxhighlight lang=ProDOS"prodos">editvar /newvar /value=a /title=Enter an integer:
editvar /newvar /value=b /title=Enter another integer:
editvar /newvar /value=c=-a-+-b-
Line 4,468 ⟶ 4,787:
=={{header|Prolog}}==
{{Works with|SWI-Prolog}}
<syntaxhighlight lang=Prolog"prolog">plus :-
read_line_to_codes(user_input,X),
atom_codes(A, X),
Line 4,476 ⟶ 4,795:
write(N).</syntaxhighlight>
output :
<syntaxhighlight lang=Prolog"prolog">?- plus.
|: 4 5
9
Line 4,482 ⟶ 4,801:
 
=={{header|Pure}}==
<syntaxhighlight lang="pure">using system;
printf "%d\n" (x+y) when x,y = scanf "%d %d" end;</syntaxhighlight>
 
=={{header|PureBasic}}==
===Console===
<syntaxhighlight lang=PureBasic"purebasic">x$=Input()
a=Val(StringField(x$,1," "))
b=Val(StringField(x$,2," "))
PrintN(str(a+b))</syntaxhighlight>
===File===
<syntaxhighlight lang=PureBasic"purebasic">If ReadFile(0,"in.txt")
x$=ReadString(0)
a=Val(StringField(x$,1," "))
Line 4,510 ⟶ 4,829:
The first two lines allow the program to be run in either Python 2 or 3. In Python 2, <code>raw_input</code> exists, and the lines are effectively skipped. In Python 3, calling <code>raw_input</code> triggers an error, so the <code>except</code> loop activates and assigns "raw_input" the value of Python 3's "input" function. Regardless of version, these two lines make sure that <code>raw_input</code> will return a string.
 
<syntaxhighlight lang="python">try: raw_input
except: raw_input = input
 
Line 4,517 ⟶ 4,836:
===File===
For Python 2.X and 3.X taking input from stdin stream which can be redirected to be file input under Unix
<syntaxhighlight lang="python">import sys
 
for line in sys.stdin:
Line 4,523 ⟶ 4,842:
 
===Console, Python 3 only===
<syntaxhighlight lang="python">a = int(input("First number: "))
b = int(input("Second number: "))
print("Result:", a+b)</syntaxhighlight>
 
=={{header|QB64}}==
<syntaxhighlight lang=QB64"qb64">DIM a AS INTEGER, b AS INTEGER
DIM c AS LONG
INPUT "Enter A: ", a
Line 4,544 ⟶ 4,863:
** Integers between -1000 and +1000.
<syntaxhighlight lang="qbasic">START:
PRINT "Enter two integers between -1000 and +1000 separated by at least one space: "
INPUT "> "; n$ ' | Enter two numbers with at least one space between.
Line 4,571 ⟶ 4,890:
 
=={{header|Quite BASIC}}==
<syntaxhighlight lang=Quite"quite BASICbasic">10 input "Enter number A: ";a
20 input "Enter number B: ";b
30 print a+b</syntaxhighlight>
 
=={{header|R}}==
<syntaxhighlight lang="r">sum(scan("", numeric(0), 2))</syntaxhighlight>
 
=={{header|Ra}}==
<syntaxhighlight lang=Ra"ra">
class Sum
**Adds two given integers**
Line 4,609 ⟶ 4,928:
=={{header|Racket}}==
 
<syntaxhighlight lang="racket">
#lang racket
(+ (read) (read))
Line 4,615 ⟶ 4,934:
 
Or, with additional error checking:
<syntaxhighlight lang="racket">
#lang racket
(define a (read))
Line 4,629 ⟶ 4,948:
 
Short version with very little "line noise":
<syntaxhighlight lang=perl6"raku" line>get.words.sum.say;</syntaxhighlight>
Reduction operator <code>[+]</code>, and <code>say</code> as a function:
<syntaxhighlight lang=perl6"raku" line>say [+] get.words;</syntaxhighlight>
Long version:
<syntaxhighlight lang=perl6"raku" line>my ($a, $b) = $*IN.get.split(" ");
say $a + $b;</syntaxhighlight>
 
=={{header|REBOL}}==
<syntaxhighlight lang="rebol">forever [x: load input print x/1 + x/2]</syntaxhighlight>
{{Out}}
<pre>1 2
Line 4,647 ⟶ 4,966:
 
=={{header|Red}}==
<syntaxhighlight lang=Red"red">x: load input print x/1 + x/2</syntaxhighlight>
{{Out}}
<pre>1 2
Line 4,657 ⟶ 4,976:
 
Alternative implementations:
<syntaxhighlight lang=Red"red">print (first x: load input) + x/2</syntaxhighlight>
<syntaxhighlight lang=Red"red">print head insert load input 'add</syntaxhighlight>
<syntaxhighlight lang=Red"red">print load replace input " " " + "</syntaxhighlight>
 
=={{header|Relation}}==
<syntaxhighlight lang=Relation"relation">
set input = "2 2"
set a = regexreplace(input,"^(-?\d+)\s+(-?\d+)+$","$1")
Line 4,670 ⟶ 4,989:
 
=={{header|Retro}}==
<syntaxhighlight lang=Retro"retro">:try ("-n) s:get s:to-number s:get s:to-number + n:put ;</syntaxhighlight>
<syntaxhighlight lang=Retro"retro">try
1
2</syntaxhighlight>
Line 4,678 ⟶ 4,997:
===version 1, unnormalized===
The numbers can be any valid REXX number (integer, fixed point decimal, floating point (with exponential notation, ···).
<syntaxhighlight lang="rexx">/*REXX program obtains two numbers from the input stream (the console), shows their sum.*/
parse pull a b /*obtain two numbers from input stream.*/
say a+b /*display the sum to the terminal. */
Line 4,690 ⟶ 5,009:
 
Dividing by one normalizes the number.
<syntaxhighlight lang="rexx">/*REXX program obtains two numbers from the input stream (the console), shows their sum.*/
parse pull a b /*obtain two numbers from input stream.*/
say (a+b) / 1 /*display normalized sum to terminal. */
Line 4,697 ⟶ 5,016:
===version 3, extended precision===
Using the &nbsp; '''numeric digits''' &nbsp; statement allows more decimal digits to be used, the default is &nbsp; '''9'''.
<syntaxhighlight lang="rexx">/*REXX program obtains two numbers from the input stream (the console), shows their sum.*/
numeric digits 300 /*the default is nine decimal digits.*/
parse pull a b /*obtain two numbers from input stream.*/
Line 4,706 ⟶ 5,025:
===version 4, multiple numbers===
This REXX version adds &nbsp; ''all'' &nbsp; the numbers entered &nbsp; (not just two).
<syntaxhighlight lang="rexx">/*REXX program obtains some numbers from the input stream (the console), shows their sum*/
numeric digits 1000 /*just in case the user gets ka-razy. */
say 'enter some numbers to be summed:' /*display a prompt message to terminal.*/
Line 4,719 ⟶ 5,038:
 
===version 5, multiple numbers, tongue in cheek===
<syntaxhighlight lang="rexx">/*REXX program obtains some numbers from the input stream (the console), shows their sum*/
numeric digits 1000 /*just in case the user gets ka-razy. */
say 'enter some numbers to be summed:' /*display a prompt message to terminal.*/
Line 4,729 ⟶ 5,048:
 
=={{header|Ring}}==
<syntaxhighlight lang="ring">give Numbers
Numbers = split(Numbers)
sum = 0
Line 4,740 ⟶ 5,059:
 
=={{header|Robotic}}==
<syntaxhighlight lang="robotic">
input string "Input A:"
set "A" to "input"
Line 4,753 ⟶ 5,072:
=={{header|Rockstar}}==
Minimized:
<syntaxhighlight lang=Rockstar"rockstar">
Listen to A number
Listen to B
Line 4,759 ⟶ 5,078:
</syntaxhighlight>
Idiomatic:
<syntaxhighlight lang=Rockstar"rockstar">
Listen to my voice
Listen to your thoughts
Shout your thoughts with my voice
</syntaxhighlight>
 
=={{header|RPL}}==
Related task is natively implemented in RPL.
+
 
2 2 +
2 3 +
{{out}}
<pre>
2: 4
1: 5
</pre>
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">puts gets.split.sum(&:to_i)</syntaxhighlight>
 
=={{header|Run BASIC}}==
<syntaxhighlight lang="runbasic">input, x$
print val(word$(x$,1)) + val(word$(x$,2))</syntaxhighlight>
 
=={{header|Rust}}==
<syntaxhighlight lang="rust">use std::io;
 
fn main() {
Line 4,788 ⟶ 5,119:
or
 
<syntaxhighlight lang="rust">use std::io;
 
fn main() {
Line 4,801 ⟶ 5,132:
 
=={{header|S-lang}}==
<syntaxhighlight lang=C"c">% A+B from stdin, sans error checking
variable input, a, b;
 
Line 4,813 ⟶ 5,144:
46</pre>
 
<syntaxhighlight lang=C"c">% A+B from stdin, basic validity testing
variable input, a, b, rc;
 
Line 4,826 ⟶ 5,157:
 
=={{header|Scala}}==
<syntaxhighlight lang="scala">println(readLine().split(" ").map(_.toInt).sum)</syntaxhighlight>
 
This will work if the input is exactly as specified, with no extra whitespace. A slightly more robust version:
 
<syntaxhighlight lang="scala">val s = new java.util.Scanner(System.in)
val sum = s.nextInt() + s.nextInt()
println(sum)</syntaxhighlight>
Line 4,836 ⟶ 5,167:
or
 
<syntaxhighlight lang="scala">println(readLine().split(" ").filter(_.length>0).map(_.toInt).sum)</syntaxhighlight>
 
=={{header|Scheme}}==
<syntaxhighlight lang="scheme">(display (+ (read) (read)))</syntaxhighlight>
 
=={{header|Scratch}}==
Line 4,848 ⟶ 5,179:
=={{header|sed}}==
Sed is for string processing and has no facility for manipulating numbers as numeric values. However, being Turing complete, sed can be coerced into performing mathematics.
<syntaxhighlight lang="sed">: Loop
# All done
/^-*00* /s///
Line 4,876 ⟶ 5,207:
 
Another method, based off of [http://unix.stackexchange.com/a/36959/11750 this StackExchange answer]:
<syntaxhighlight lang="sed">#!/bin/sed -f
 
# Add a marker in front of each digit, for tracking tens, hundreds, etc.
Line 4,917 ⟶ 5,248:
 
=={{header|Seed7}}==
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
const proc: main is func
Line 4,932 ⟶ 5,263:
Works with positive and negative integers, and also more than two integers.
 
<syntaxhighlight lang="self">((stdin readLine splitOn: ' ') mapBy: [|:e| e asInteger]) sum printLine.</syntaxhighlight>
 
=={{header|SenseTalk}}==
<syntaxhighlight lang="sensetalk">ask "Enter the first number:"
put it into a
 
Line 4,942 ⟶ 5,273:
 
put a + b</syntaxhighlight>
<syntaxhighlight lang="sensetalk">put file "input.txt" into inputFile
split inputFile by space
put sum of inputFile</syntaxhighlight>
 
=={{header|SequenceL}}==
<syntaxhighlight lang="sequencel">import <Utilities/Conversion.sl>;
 
main(args(2)) := stringToInt(args[1]) + stringToInt(args[2]);</syntaxhighlight>
Line 4,962 ⟶ 5,293:
 
=={{header|SETL}}==
<syntaxhighlight lang="setl">read(A, B);
print(A + B);</syntaxhighlight>
 
=={{header|Shiny}}==
<syntaxhighlight lang="shiny">if (io.line 'stdin').match ~(\d+)\s+(\d+)~
say "$a $b %(a+b)d"
end</syntaxhighlight>
Line 4,972 ⟶ 5,303:
=={{header|Sidef}}==
Works with both positive and negative integers.
<syntaxhighlight lang="ruby">say STDIN.readline.words.map{.to_i}.sum</syntaxhighlight>
 
More idiomatically:
<syntaxhighlight lang="ruby">say read(String).words»to_i»()»«+»</syntaxhighlight>
 
Explicit summation:
<syntaxhighlight lang="ruby">var (a, b) = read(String).words.map{.to_i}...
say a+b</syntaxhighlight>
 
=={{header|Simula}}==
<syntaxhighlight lang="simula">BEGIN
WHILE NOT LASTITEM DO
BEGIN
Line 4,993 ⟶ 5,324:
=={{header|Smalltalk}}==
Most Smalltalk implementations do not have the notion of a standard input stream, since it has always been a GUI based programming environment. I've included test methods to demonstrate one way to create an input stream with two integers can be created. Opening a text file would be another.
<syntaxhighlight lang="smalltalk">'From Squeak3.7 of ''4 September 2004'' [latest update: #5989] on 8 August 2011 at 3:50:55 pm'!
Object subclass: #ABTask
instanceVariableNames: ''
Line 5,027 ⟶ 5,358:
{{works with|Smalltalk/X}}
{{works with|VisualWorks Smalltalk}}
<syntaxhighlight lang="smalltalk">|task|
task := [:inStream :outStream |
|processLine|
Line 5,047 ⟶ 5,378:
task value: ( 'dataIn.txt' asFilename readStream) value:Transcript.</syntaxhighlight>
or:
<syntaxhighlight lang="smalltalk">task value: Stdin value: Stdout.</syntaxhighlight>
 
=={{header|smart BASIC}}==
<syntaxhighlight lang="qbasic">INPUT n$
PRINT VAL(LEFT$(n$,(LEN(STR$(VAL(n$))))))+VAL(RIGHT$(n$,(LEN(n$)-LEN(STR$(VAL(n$)))-1)))</syntaxhighlight>
 
Line 5,059 ⟶ 5,390:
A FAR more elegant solution was provided by "Dutchman" on the smart [http://kibernetik.pro/forum/viewforum.php?f=2 BASIC Support Forum]:
 
<syntaxhighlight lang="qbasic">INPUT n$
SPLIT n$ TO m$,n WITH " "
PRINT m$(0),m$(1),m$(0)+m$(1)</syntaxhighlight>
Line 5,066 ⟶ 5,397:
 
=={{header|SmileBASIC}}==
<syntaxhighlight lang="smilebasic">INPUT A
INPUT B
PRINT A+B
Line 5,073 ⟶ 5,404:
=={{header|SNOBOL4}}==
Simple-minded solution (literally "two somethings separated by space")
<syntaxhighlight lang="snobol"> input break(" ") . a " " rem . b
output = a + b
end</syntaxhighlight>
"Integer aware" solution:
<syntaxhighlight lang="snobol"> nums = "0123456789"
input span(nums) . a break(nums) span(nums) . b
output = a + b
Line 5,087 ⟶ 5,418:
{{works with|Axiom}}
One of several possibilities:
<syntaxhighlight lang=SPAD"spad">(1) -> integer READ()$Lisp + integer READ()$Lisp
333 444
 
Line 5,094 ⟶ 5,425:
 
Domain:[http://fricas.github.io/api/SExpression.html?highlight=lisp SExpression]
 
=={{header|SparForte}}==
As a structured script.
<syntaxhighlight lang="ada">#!/usr/local/bin/spar
pragma annotate( summary, "aplusb" )
@( description, "A+B - in programming contests, classic problem, which is given so" )
@( description, "contestants can gain familiarity with online judging system being used. " )
@( description, "A+B is one of few problems on contests, which traditionally lacks fabula." )
@( description, "Given 2 integer numbers, A and B. One needs to find their sum. " )
@( category, "tutorials" )
@( author, "Ken O. Burtch" )
@( see_also, "http://rosettacode.org/wiki/A%2BB" );
pragma license( unrestricted );
 
pragma software_model( nonstandard );
pragma restriction( no_external_commands );
 
procedure aplusb is
s : string;
a : integer;
b : integer;
begin
s := get_line;
a := numerics.value( strings.field( s, 1, ' ' ) );
b := numerics.value( strings.field( s, 2, ' ' ) );
? a+b;
end aplusb;</syntaxhighlight>
 
=={{header|SPARK}}==
<syntaxhighlight lang=Ada"ada">-- By Jacob Sparre Andersen
-- Validates with SPARK GPL 2010's Examiner/Simplifier
 
Line 5,142 ⟶ 5,500:
 
=={{header|SPL}}==
<syntaxhighlight lang="spl">n = #.split(#.input("Input two numbers, separated by space:")," ")
#.output(n[1],"+",n[2],"=",#.val(n[1])+#.val(n[2]))</syntaxhighlight>
{{in}}
Line 5,155 ⟶ 5,513:
 
=={{header|SQL}}==
<syntaxhighlight lang="sql">select A+B</syntaxhighlight>
Example:
<syntaxhighlight lang="sql">select 2+3</syntaxhighlight>
This should produce a result set containing the value 5.
 
Line 5,165 ⟶ 5,523:
{{works with|Db2 LUW}}
With SQL only:
<syntaxhighlight lang="sql pl">
 
CREATE OR REPLACE FUNCTION splitadd (instring VARCHAR(255))
Line 5,191 ⟶ 5,549:
=={{header|SSEM}}==
The SSEM has no Add instruction, so we rely on the fact that <i>a</i> + <i>b</i> = -(-<i>a</i> - <i>b</i>).
<syntaxhighlight lang="ssem">10100000000000100000000000000000 0. -5 to c acc = -A
01100000000001010000000000000000 1. Sub. 6 acc -= B
11100000000001100000000000000000 2. c to 7 X = acc
Line 5,201 ⟶ 5,559:
 
=={{header|Standard ML}}==
<syntaxhighlight lang="sml">(*
* val split : string -> string list
* splits a string at it spaces
Line 5,233 ⟶ 5,591:
{{works with|Swift|2}}
Requires sending EOF.
<syntaxhighlight lang=Swift"swift">import Foundation
 
let input = NSFileHandle.fileHandleWithStandardInput()
Line 5,250 ⟶ 5,608:
Swift 4 and no requirement to send EOF (press enter/send newline like you normally would)
 
<syntaxhighlight lang=Swift"swift">
import Foundation
 
Line 5,268 ⟶ 5,626:
 
=={{header|Symsyn}}==
<syntaxhighlight lang=Symsyn"symsyn">
 
[] $s
Line 5,279 ⟶ 5,637:
 
=={{header|Tailspin}}==
<syntaxhighlight lang="tailspin">
composer nums
[ (<WS>?) <INT> (<WS>) <INT> (<WS>?) ]
Line 5,289 ⟶ 5,647:
 
Alternatively
<syntaxhighlight lang="tailspin">
composer nums
(<WS>?) (def a: <INT>;) (<WS>) <INT> -> $a + $ (<WS>?)
Line 5,299 ⟶ 5,657:
 
=={{header|Tcl}}==
<syntaxhighlight lang="tcl">scan [gets stdin] "%d %d" x y
puts [expr {$x + $y}]</syntaxhighlight>
Alternatively:
<syntaxhighlight lang="tcl">puts [tcl::mathop::+ {*}[gets stdin]]</syntaxhighlight>
To/from a file:
<syntaxhighlight lang="tcl">set in [open "input.txt"]
set out [open "output.txt" w]
scan [gets $in] "%d %d" x y
Line 5,312 ⟶ 5,670:
 
=={{header|Terraform}}==
<syntaxhighlight lang="hcl">
#Aamrun, August 15th, 2022
 
Line 5,345 ⟶ 5,703:
 
=={{header|TI-83 BASIC}}==
<syntaxhighlight lang="ti83b">:Prompt A,B
:Disp A+B</syntaxhighlight>
 
Line 5,352 ⟶ 5,710:
Note: Comments (after the semicolons) are just for explanation -- TI-83 hex assembly does not allow comments in program source code.
 
<syntaxhighlight lang="ti83b">PROGRAM:APLUSB
:AsmPrgm
:
Line 5,373 ⟶ 5,731:
 
=={{header|TI-89 BASIC}}==
<syntaxhighlight lang="ti89b">:aplusb(a,b)
:a+b</syntaxhighlight>
 
Line 5,379 ⟶ 5,737:
Since torque is not compatible with standard input, I will show the closest to that.
It's a function that takes a single string input, that will contain the 2 numbers.
<syntaxhighlight lang=Torque"torque">Function aPlusB(%input)
{
return getWord(%input, 0) + getWord(%input, 1);
Line 5,385 ⟶ 5,743:
 
=={{header|Transd}}==
<syntaxhighlight lang="scheme">#lang transd
 
MainModule : {
Line 5,394 ⟶ 5,752:
 
=={{header|TSE SAL}}==
<syntaxhighlight lang=TSESAL"tsesal">
INTEGER PROC FNMathGetSumAPlusBI( INTEGER A, INTEGER B )
RETURN( A + B )
Line 5,413 ⟶ 5,771:
 
=={{header|TUSCRIPT}}==
<syntaxhighlight lang="tuscript">$$ MODE TUSCRIPT
SET input="1 2"
SET input=SPLIT(input,": :")
Line 5,434 ⟶ 5,792:
=={{header|UNIX Shell}}==
{{works with|Bourne Shell}}
<syntaxhighlight lang="sh">#!/bin/sh
read a b || exit
echo `expr "$a" + "$b"`</syntaxhighlight>
Line 5,443 ⟶ 5,801:
{{works with|zsh}}
Script "a+b.sh":
<syntaxhighlight lang="bash">#!/bin/bash
read a b || exit
echo $(( a + b ))</syntaxhighlight>
{{Out}}
<syntaxhighlight lang="bash">echo 2 3 | ksh a+b.sh
5</syntaxhighlight>
 
One liner :
 
<syntaxhighlight lang="bash">
a=0;b=0;read a;read b;echo "Sum of $a and $b is "$((a+b))
</syntaxhighlight>
Line 5,463 ⟶ 5,821:
 
==={{header|C Shell}}===
<syntaxhighlight lang="csh">set line=$<
set input=($line)
@ sum = $input[1] + $input[2]
Line 5,469 ⟶ 5,827:
 
=={{header|Ursa}}==
<syntaxhighlight lang="text">#
# a + b
#
Line 5,487 ⟶ 5,845:
=={{header|Ultimate++}}==
 
<syntaxhighlight lang=Cpp"cpp">
#include <Core/Core.h>
#include <stdio.h>
Line 5,513 ⟶ 5,871:
=={{header|Ursala}}==
Using standard input and output streams:
<syntaxhighlight lang=Ursala"ursala">#import std
#import int
 
Line 5,520 ⟶ 5,878:
main = %zP+ sum:-0+ %zp*FiNCS+ sep` @L</syntaxhighlight>
Overwriting a text file named as a command line parameter:
<syntaxhighlight lang=Ursala"ursala">#import std
#import int
 
Line 5,527 ⟶ 5,885:
main = ~command.files.&h; <.contents:= %zP+ sum:-0+ %zp*FiNCS+ sep` @L+ ~contents></syntaxhighlight>
Creating a new file named after the input file with suffix <code>.out</code>:
<syntaxhighlight lang=Ursala"ursala">#import std
#import int
 
Line 5,540 ⟶ 5,898:
=={{header|Vala}}==
Read from stdin while program running:
<syntaxhighlight lang="vala">Using GLib;
 
int main (string[] args) {
Line 5,554 ⟶ 5,912:
=={{header|VBA}}==
A simple version:
<syntaxhighlight lang=VBA"vba">Sub AplusB()
Dim s As String, t As Variant, a As Integer, b As Integer
s = InputBox("Enter two numbers separated by a space")
Line 5,563 ⟶ 5,921:
End Sub</syntaxhighlight>
An other version:
<syntaxhighlight lang=VBA"vba">Sub Rosetta_AB()
Dim stEval As String
stEval = InputBox("Enter two numbers, separated only by a space", "Rosetta Code", "2 2")
Line 5,573 ⟶ 5,931:
=={{header|VBScript}}==
A simple version:
<syntaxhighlight lang="vb">s=InputBox("Enter two numbers separated by a blank")
t=Split(s)
a=CInt(t(0))
Line 5,580 ⟶ 5,938:
MsgBox c </syntaxhighlight>
An other version:
<syntaxhighlight lang="vb">Option Explicit
Dim a, b
Select Case WScript.Arguments.Count
Line 5,617 ⟶ 5,975:
End With
end if</syntaxhighlight>
 
=={{header|Vedit macro language}}==
This version implements the task as specified in the task description.
<syntaxhighlight lang="vedit">// Input two values on single line in text format
Get_Input(10, "Enter two integers separated by a space: ")
 
// Extract two numeric values from the text
Buf_Switch(Buf_Free)
Reg_Ins(10)
BOF
#1 = Num_Eval(ADVANCE)
#2 = Num_Eval()
Buf_Quit(OK)
 
// Calculate and display the results
Num_Type(#1 + #2)</syntaxhighlight>
 
A simpler version that prompts for the two numbers separately:
<syntaxhighlight lang="vedit">#1 = Get_Num("Enter number A: ")
#2 = Get_Num("Enter number B: ")
Num_Type(#1 + #2)</syntaxhighlight>
 
=={{header|Verilog}}==
<syntaxhighlight lang=Verilog"verilog">module TEST;
 
reg signed [11:0] y;
Line 5,640 ⟶ 6,019:
 
=={{header|VHDL}}==
<syntaxhighlight lang=VHDL"vhdl">LIBRARY std;
USE std.TEXTIO.all;
 
Line 5,665 ⟶ 6,044:
 
=={{header|Visual Basic .NET}}==
<syntaxhighlight lang="vbnet">Module Module1
 
Sub Main()
Line 5,676 ⟶ 6,055:
End Module</syntaxhighlight>
 
=={{header|V (Vlang)}}==
<syntaxhighlight lang="go">import os
 
fn main() {
Line 5,701 ⟶ 6,080:
 
=={{header|Wee Basic}}==
<syntaxhighlight lang=Wee"wee Basicbasic">Print 1 "Enter number A:"
input a
Print 1 "Enter number B:"
Line 5,710 ⟶ 6,089:
 
=={{header|Whitespace}}==
<syntaxhighlight lang="whitespace">
Line 5,726 ⟶ 6,105:
=={{header|Wisp}}==
{{trans|Scheme}}
<syntaxhighlight lang="scheme">
display : + (read) (read)
 
Line 5,736 ⟶ 6,115:
 
=={{header|Wren}}==
<syntaxhighlight lang=ecmascript"wren">import "io" for Stdin, Stdout
 
while (true) {
Line 5,761 ⟶ 6,140:
=={{header|X86 Assembly}}==
{{works with|NASM|Linux}}
<syntaxhighlight lang="asm">section .text
global _start
Line 5,825 ⟶ 6,204:
=={{header|XBS}}==
Since XBS is written in Javascript, we have to use the Javascript prompt function to get inputs.
<syntaxhighlight lang="xbs">const Amount:number = toint(window.prompt("Input an amount"));
set Stream = [];
<|(*1..Amount)=>Stream.push(window.prompt("Input a number"));
Line 5,840 ⟶ 6,219:
 
=={{header|xEec}}==
<syntaxhighlight lang=xEec"xeec">i# i# ma h#10 r o# p o$ p</syntaxhighlight>
 
=={{header|XLISP}}==
<syntaxhighlight lang="xlisp">(DEFUN A-PLUS-B ()
(DISPLAY "Enter two numbers separated by a space.")
(NEWLINE)
Line 5,858 ⟶ 6,237:
 
=={{header|Xojo}}==
<syntaxhighlight lang="xojo">var inp as string
var strVals() as string
 
Line 5,887 ⟶ 6,266:
 
=={{header|XPL0}}==
<syntaxhighlight lang=XPL0"xpl0">include c:\cxpl\codes;
int A, B;
[A:= IntIn(0);
Line 5,896 ⟶ 6,275:
 
=={{header|XQuery}}==
<syntaxhighlight lang="xquery">
(:
Using the EXPath File Module, which is built into most XQuery processors
Line 5,915 ⟶ 6,294:
 
=={{header|Yabasic}}==
<syntaxhighlight lang=Yabasic"yabasic">repeat
input "Enter two numbers (betwen -1000 ... +1000): " a, b
until(valid(a) and valid(b))
Line 5,925 ⟶ 6,304:
 
=={{header|Yorick}}==
<syntaxhighlight lang="yorick">a = b = 0;
read, a, b;
write, a + b;</syntaxhighlight>
Line 5,932 ⟶ 6,311:
Source -> http://ideone.com/WLtEfe
Compiled -> http://ideone.com/fMt6ST
<syntaxhighlight lang="zed">(A+B)
comment:
#true
Line 5,948 ⟶ 6,327:
 
=={{header|zkl}}==
<syntaxhighlight lang="zkl">do(2){ask("A B: ").split(" ").filter().sum().println()}</syntaxhighlight>
<pre>
A B: 123 567
Line 5,958 ⟶ 6,337:
 
=={{header|Zoea}}==
<syntaxhighlight lang=Zoea"zoea">program: a_plus_b
input: '7 11'
output: 18
Line 5,967 ⟶ 6,346:
 
=={{header|zonnon}}==
<syntaxhighlight lang="zonnon">
module ABProblem;
var
Line 5,982 ⟶ 6,361:
 
=={{header|ZX Spectrum Basic}}==
<syntaxhighlight lang="zxbasic">10 PRINT "Input two numbers separated by"'"space(s) "
20 INPUT LINE a$
30 GO SUB 90
Line 5,995 ⟶ 6,374:
Another solution
 
<syntaxhighlight lang="zxbasic">10 PRINT "Input two numbers separated by"'"space(s) "
20 INPUT LINE a$
30 LET ll=10e10: LET ls=0: LET i=1
62

edits