A+B: Difference between revisions

10,397 bytes added ,  1 year ago
m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
Line 32:
 
=={{header|0815}}==
<syntaxhighlight lang =0815>|x|+%</langsyntaxhighlight>
 
=={{header|11l}}==
{{trans|Python}}
<langsyntaxhighlight lang=11l>print(sum(input().split(‘ ’, group_delimiters' 1B).map(i -> Int(i))))</langsyntaxhighlight>
 
=={{header|360 Assembly}}==
<langsyntaxhighlight lang=360asm>* A+B 29/08/2015
APLUSB CSECT
USING APLUSB,R12
Line 60:
YREGS
END APLUSB
</syntaxhighlight>
</lang>
{{in}}
<pre>
Line 75:
 
=={{header|8th}}==
<langsyntaxhighlight lang=forth>gets dup . space eval n:+ . cr</langsyntaxhighlight>
 
=={{header|8080 Assembly}}==
Line 86:
which can take four forms:
 
<langsyntaxhighlight 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")
dad sp ; HL += SP (actually the only way to get at SP at all)</langsyntaxhighlight>
 
Merely doing A+B, with 16-bit numbers so that <math>(-1000 \le A,B \le +1000)</math> will fit,
would look like this:
<langsyntaxhighlight lang=8080asm> lxi h,123
lxi d,456
dad d
; HL is now 579</langsyntaxhighlight>
 
Then, the following is what is required to wrap it all in a CP/M command line utility.
Line 104:
fits exactly in one CP/M block.
 
<langsyntaxhighlight 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 193:
negf: db 0 ; Space for negative flag
db '-00000'
num: db '$' ; Space for number</langsyntaxhighlight>
 
{{out}}
Line 209:
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<langsyntaxhighlight lang=AArch64 Assembly>
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program addAetB.s */
Line 406:
.align 4 // instruction to realign the following routines
 
</syntaxhighlight>
</lang>
 
=={{header|ABAP}}==
<langsyntaxhighlight lang=ABAP>report z_sum_a_b.
data: lv_output type i.
selection-screen begin of block input.
Line 423:
start-of-selection.
lv_output = p_first + p_second.
write : / lv_output.</langsyntaxhighlight>
 
=={{header|Action!}}==
<langsyntaxhighlight lang=Action!>BYTE FUNC Find(CHAR ARRAY s CHAR c BYTE POINTER err)
BYTE i
FOR i=1 TO s(0)
Line 487:
PutE();
OD
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/A+B.png Screenshot from Atari 8-bit computer]
Line 503:
 
=={{header|Ada}}==
<langsyntaxhighlight lang=Ada>-- Standard I/O Streams
 
with Ada.Integer_Text_Io;
Line 512:
Ada.Integer_Text_Io.Get (Item => B);
Ada.Integer_Text_Io.Put (A+B);
end APlusB;</langsyntaxhighlight>
Using appropriate user defined types:
<langsyntaxhighlight lang=Ada>with Ada.Text_IO;
 
procedure A_Plus_B is
Line 525:
IO.Get (B);
IO.Put (A + B, Width => 4, Base => 10);
end A_Plus_B;</langsyntaxhighlight>
 
=={{header|Agena}}==
Tested with Agena 2.9.5 Win32
<langsyntaxhighlight lang=agena>scope
local f := trim( io.read() ) split " "; # read a line and split into fields
local a := tonumber( f[ 1 ] );
local b := tonumber( f[ 2 ] );
print( a + b )
epocs</langsyntaxhighlight>
 
=={{header|Aime}}==
<langsyntaxhighlight lang=aime>file f;
list l;
 
Line 543:
f_list(f, l, 0);
o_integer(atoi(l[0]) + atoi(l[1]));
o_newline();</langsyntaxhighlight>
 
=={{header|ALGOL 60}}==
{{works with|A60}}
<langsyntaxhighlight lang=algol60>begin
comment A+B;
integer a,b;
ininteger(0,a); ininteger(0,b);
outinteger(1,a+b)
end </langsyntaxhighlight>
{{in}}
<pre>
Line 569:
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - missing transput function "read int"}}
===Console===
<langsyntaxhighlight lang=algol68>print((read int + read int))</langsyntaxhighlight>
Input:
<pre>
Line 580:
 
===File===
<langsyntaxhighlight lang=algol68>open(stand in, "input.txt", stand in channel);
open(stand out, "output.txt", stand out channel);
print((read int + read int))</langsyntaxhighlight>
Input "input.txt":
<pre>
Line 593:
 
=={{header|ALGOL W}}==
<langsyntaxhighlight lang=algolw>begin
integer a, b;
read( a, b );
write( a + b )
end.</langsyntaxhighlight>
 
=={{header|Amazing Hopper}}==
<langsyntaxhighlight lang=Amazing Hopper>
#include <hbasic.h>
 
Line 615:
Print("Suma : ", Token(1),Val(Token$(msg)) Plus (Token(2),Val(Token$(msg))), Newl)
End
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 625:
Version dos: hopper-BASIC acepta "programación fluída"
 
<langsyntaxhighlight lang=Amazing Hopper>
#include <hbasic.h>
 
Line 646:
Take(A, B), and Add It; then Print It with a Newl
End
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 660:
 
=={{header|Apex}}==
<langsyntaxhighlight lang=Apex>
 
static Integer sumOfTwoNums(Integer A, Integer B) {
Line 677:
A = 50 and B = -25: 25
 
</syntaxhighlight>
</lang>
 
=={{header|APL}}==
<syntaxhighlight lang =APL> ⎕+⎕ </langsyntaxhighlight>
 
=={{header|AppleScript}}==
Open the '''AppleScript Editor''' and save this as '''A+B.scpt''' on your Desktop
<langsyntaxhighlight lang=AppleScript>on run argv
try
return ((first item of argv) as integer) + (second item of argv) as integer
Line 690:
return "Usage with -1000 <= a,b <= 1000: " & tab & " A+B.scpt a b"
end try
end run</langsyntaxhighlight>
 
To make this run in Terminal open the '''Terminal.app''' and type
Line 700:
 
=={{header|Arc}}==
<langsyntaxhighlight lang=Arc>
(prn (+ (read)
(read)))
</syntaxhighlight>
</lang>
 
=={{header|Argile}}==
{{trans|C}}
{{works with|Argile|1.0.0}}
<langsyntaxhighlight lang=Argile>(: Standard input-output streams :)
use std, array
Cfunc scanf "%d%d" (&val int a) (&val int b)
printf "%d\n" (a + b)</langsyntaxhighlight>
<langsyntaxhighlight lang=Argile>(: Input file : input.txt :)
(: Output file: output.txt :)
use std, array
Line 721:
fprintf out "%d\n" (x+y)
fclose in
fclose out</langsyntaxhighlight>
 
=={{header|ARM Assembly}}==
Line 727:
Exploiting C standard library functions (scanf and printf).
Requires arm-linux-gnueabi-gcc and qemu-arm. Compile with:
<langsyntaxhighlight lang=ARM_Assembly>arm-linux-gnueabi-as src.s -o src.o && arm-linux-gnueabi-gcc -static src.o -o run && qemu-arm run</langsyntaxhighlight>
 
<langsyntaxhighlight lang=ARM_Assembly>.text
.global main
.extern printf
Line 755:
.bss
num_a: .skip 4
num_b: .skip 4</langsyntaxhighlight>
 
{{works with|gcc|Linux}}
Line 775:
Save in ab.S
Build with:
<langsyntaxhighlight lang=ARM_Assembly>as -o ab.o ab.S
ld -o a.out ab.o</langsyntaxhighlight>
 
<langsyntaxhighlight lang=ARM_Assembly>.data
.align 2
.code 32
Line 1,291:
movlt r0, #0
ldmfd sp!, {r7, pc}
</syntaxhighlight>
</lang>
 
=={{header|Arturo}}==
 
<langsyntaxhighlight lang=rebol>while ø [
x: map split.words input "give me 2 numbers:" 'x -> to :integer x
print add x\0 x\1
]
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,316:
 
=={{header|ATS}}==
<langsyntaxhighlight lang=ATS>
(* ****** ****** *)
//
Line 1,343:
 
(* ****** ****** *)
</syntaxhighlight>
</lang>
 
=={{header|AutoHotkey}}==
This handles more than two inputs
<langsyntaxhighlight lang=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,359:
GuiControl, Text, Edit2, %var% ;here it displays var in the second edit control
var := 0 ;here it makes sure var is 0 so it won't contain the value from the previous addition
return</langsyntaxhighlight>
 
=={{header|AutoIt}}==
<langsyntaxhighlight lang=AutoIt>;AutoIt Version: 3.2.10.0
$num = "45 54"
consolewrite ("Sum of " & $num & " is: " & sum($num))
Line 1,368:
$numm = StringSplit($numbers," ")
Return $numm[1]+$numm[$numm[0]]
EndFunc</langsyntaxhighlight>
 
===Example2===
This version can handle any amount of numbers in the input:
<langsyntaxhighlight lang=AutoIt>ConsoleWrite("# A+B:" & @CRLF)
 
Func Sum($inp)
Line 1,393:
; so the program works correctly even with this input:
Local $inp = "999x y 42 -999", $res = Sum($inp)
ConsoleWrite($inp & " --> " & $res & @CRLF)</langsyntaxhighlight>
{{Out}}
<pre>
Line 1,402:
 
=={{header|AWK}}==
<langsyntaxhighlight lang=awk>{print $1 + $2}</langsyntaxhighlight>
 
=={{header|BASIC}}==
<langsyntaxhighlight lang=qbasic>DEFINT A-Z
 
tryagain:
Line 1,420:
ELSE
GOTO tryagain
END IF</langsyntaxhighlight>
 
==={{header|Applesoft BASIC}}===
<langsyntaxhighlight lang=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,433:
100 VTAB BH
110 HTAB LEN(A$) + 2 + S
120 PRINT C%</langsyntaxhighlight>
 
==={{header|BaCon}}===
<langsyntaxhighlight lang=qbasic>' A+B
INPUT d$
PRINT VAL(TOKEN$(d$, 1)) + VAL(TOKEN$(d$, 2))</langsyntaxhighlight>
 
==={{header|BASIC256}}===
<langsyntaxhighlight lang=basic256>dim a(2)
input "Enter two numbers separated by a space?", t$
a = explode(t$," ")
print t$ & " " & int(a[0]) + int(a[1])</langsyntaxhighlight>
 
==={{header|BBC BASIC}}===
<langsyntaxhighlight lang=bbc> REPEAT
hereY% = VPOS
INPUT LINE "" q$
Line 1,460:
PRINT TAB(hereX%, hereY%) ; a + b
ENDIF
UNTIL FALSE</langsyntaxhighlight>
That seems overly complicated. What's wrong with:
<langsyntaxhighlight lang=bbc> REPEAT
INPUT LINE "" q$
space% = INSTR(q$," ")
PRINT VAL LEFT$(q$,space%-1) + VAL MID$(q$,space%+1)
UNTIL FALSE</langsyntaxhighlight>
 
==={{header|Commodore BASIC}}===
<langsyntaxhighlight lang=qbasic>10 PRINT "ENTER TWO NUMBERS, SEPARATED BY A SPACE: ";
20 INPUT X$
30 I = 1 : N = LEN(X$)
Line 1,475:
50 A = VAL(LEFT$(X$,I))
60 B = VAL(RIGHT$(X$,N-1))
70 PRINT A+B</langsyntaxhighlight>
 
==={{header|FreeBASIC}}===
<langsyntaxhighlight lang=freebasic>' fb 1.05.0 Win64
 
Dim As Integer a, b
Line 1,494:
Print
Print "Press any key to quit the program"
Sleep</langsyntaxhighlight>
 
==={{header|FUZE BASIC}}===
<langsyntaxhighlight lang=qbasic>INPUT n$
PRINT VAL(LEFT$(n$,(LEN(STR$(VAL(n$))))))+VAL(RIGHT$(n$,(LEN(n$)-LEN(STR$(VAL(n$)))-1)))
END</langsyntaxhighlight>
 
==={{header|IS-BASIC}}===
<langsyntaxhighlight lang=IS-BASIC>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,510:
160 EXIT DO
170 END IF
180 LOOP</langsyntaxhighlight>
 
==={{header|Liberty BASIC}}===
<langsyntaxhighlight lang=lb>input, n$
print eval(word$(n$,1);" + ";word$(n$,2))</langsyntaxhighlight>
 
==={{header|OxygenBasic}}===
Line 1,530:
print val(s)+val(mid(s,i))+cr
loop
</syntaxhighlight>
</lang>
 
==={{header|Sinclair ZX81 BASIC}}===
<langsyntaxhighlight lang=basic>10 INPUT A$
20 LET I=1
30 IF A$(I)=" " THEN GOTO 60
40 LET I=I+1
50 GOTO 30
60 PRINT VAL A$( TO I-1)+VAL A$(I+1 TO )</langsyntaxhighlight>
 
==={{Header|Tiny BASIC}}===
<langsyntaxhighlight lang=Tiny BASIC>REM Rosetta Code problem: https://rosettacode.org/wiki/A+B
REM by Jjuanhdez, 06/2022
 
Line 1,558:
60 PRINT "Both integers must be in the range [-1000..1000] - try again."
GOTO 10
70 END</langsyntaxhighlight>
 
==={{header|True BASIC}}===
<langsyntaxhighlight 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,571:
END IF
LOOP
END</langsyntaxhighlight>
==={{header|uBasic/4tH}}===
<lang>s = FUNC(_GetInt(1000)) + FUNC(_GetInt(1000))
Line 1,586:
Print "Wrong, must be between "; -a@; " and "; a@; ". Try again.."
Loop
Return (b@)</langsyntaxhighlight>
 
=={{header|Batch File}}==
Prompts version
<langsyntaxhighlight lang=dos>::aplusb.cmd
@echo off
setlocal
Line 1,597:
set /a c=a+b
echo %c%
endlocal</langsyntaxhighlight>
All on the commandline version
<langsyntaxhighlight lang=dos>::aplusb.cmd
@echo off
setlocal
Line 1,606:
set /a c=a+b
echo %c%
endlocal</langsyntaxhighlight>
Formula on the command line version
<langsyntaxhighlight lang=dos>::aplusb.cmd
@echo off
setlocal
set /a c=%~1
echo %c%
endlocal</langsyntaxhighlight>
Example of 'Formula on the command line version'
<pre>
Line 1,622:
</pre>
Parse the input stream version (thanks to Tom Lavedas on alt.msdos.batch.nt)
<langsyntaxhighlight lang=dos>::aplusb.cmd
@echo off
setlocal
Line 1,634:
set /a res=res+%1
shift
if "%1" neq "" goto :add</langsyntaxhighlight>
Example of 'parse the input stream version'
<pre>>aplusb
Line 1,645:
=={{header|bc}}==
{{Works with|GNU bc}}
<syntaxhighlight lang =bc>read() + read()</langsyntaxhighlight>
 
=={{header|Befunge}}==
<syntaxhighlight lang =befunge>&&+.@</langsyntaxhighlight>
 
=={{header|Bird}}==
<langsyntaxhighlight lang=Bird>use Console Math
 
define Main
Line 1,657:
$b Console.Read
Console.Println Math.Add $a $b
end</langsyntaxhighlight>
 
=={{header|BlooP}}==
Line 1,670:
=={{header|bootBASIC}}==
Both numbers are entered separately.
<langsyntaxhighlight lang=bootBASIC>10 print "Number 1";
20 input a
30 print "Number 2";
40 input b
50 print a+b</langsyntaxhighlight>
 
=={{header|BQN}}==
Line 1,680:
{{works with|https://github.com/dzaima/CBQN CBQN}}
 
<langsyntaxhighlight lang=bqn>#!/usr/bin/env bqn
 
# Cut 𝕩 at occurrences of 𝕨, removing separators and empty segments
Line 1,693:
 
# •GetLine and •_while_ are nonstandard CBQN extensions.
{•Show +´ ParseNums 𝕩 ⋄ •GetLine@} •_while_ (@⊸≢) •GetLine@</langsyntaxhighlight>
 
=={{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.
<langsyntaxhighlight lang=bracmat>( out
$ ( put$"Enter two integer numbers between -1000 and 1000:"
& (filter=~/#%:~<-1000:~>1000)
Line 1,704:
| "Invalid input. Try again"
)
);</langsyntaxhighlight>
 
=={{header|Brainf***}}==
<langsyntaxhighlight lang=brainf***>INPUT AND SUMMATION
TODO if first symbol is a minus sign print Qgo awayQ
+> initialize sum to one
Line 1,730:
>++++++++++++++++++++++++++++++++++++++++++++++++> convert remainder to ascii digit
]
<[.<<] print ascii digits</langsyntaxhighlight>
 
=={{header|Brat}}==
<langsyntaxhighlight lang=brat>numbers = g.split[0,1].map(:to_i)
p numbers[0] + numbers[1] #Prints the sum of the input</langsyntaxhighlight>
 
=={{header|Burlesque}}==
<syntaxhighlight lang =burlesque>ps++</langsyntaxhighlight>
 
=={{header|C}}==
<langsyntaxhighlight lang=c>// Standard input-output streams
#include <stdio.h>
int main()
Line 1,748:
printf("%d\n", a + b);
return 0;
}</langsyntaxhighlight>
<langsyntaxhighlight lang=c>// Input file: input.txt
// Output file: output.txt
#include <stdio.h>
Line 1,760:
printf("%d\n", a + b);
return 0;
}</langsyntaxhighlight>
<syntaxhighlight lang=c>
<lang c>
#include <stdio.h>
#include <stdlib.h>
Line 1,769:
return 0;
}
</syntaxhighlight>
</lang>
 
=={{header|C sharp|C#}}==
<langsyntaxhighlight lang=csharp>using System;
using System.Linq;
 
Line 1,781:
Console.WriteLine(Console.ReadLine().Split().Select(int.Parse).Sum());
}
}</langsyntaxhighlight>
Another way (not recommended since it does not work with more than two numbers):
<langsyntaxhighlight lang=csharp>using System;
 
class Program
Line 1,796:
Console.WriteLine(sum.ToString());
}
}</langsyntaxhighlight>
 
=={{header|C++}}==
<langsyntaxhighlight lang=cpp>// Standard input-output streams
#include <iostream>
using namespace std;
Line 1,807:
cin >> a >> b;
cout << a + b << endl;
}</langsyntaxhighlight>
<langsyntaxhighlight lang=cpp>// Input file: input.txt
// Output file: output.txt
#include <fstream>
Line 1,820:
out << a + b << endl;
return 0;
}</langsyntaxhighlight>
 
=={{header|Ceylon}}==
<langsyntaxhighlight lang=ceylon>shared void run() {
 
print("please enter two numbers for me to add");
Line 1,847:
}
}
}</langsyntaxhighlight>
 
=={{header|Clojure}}==
<langsyntaxhighlight lang=clojure>(println (+ (Integer/parseInt (read-line)) (Integer/parseInt (read-line))))
3
4
=>7</langsyntaxhighlight>
<langsyntaxhighlight lang=clojure>(eval (read-string (str "(+ " (read-line) " )") ))
3 3
6</langsyntaxhighlight>
 
Translation of Common Lisp version:
<langsyntaxhighlight lang=clojure>(println (+ (read) (read)))
3 4
7</langsyntaxhighlight>
 
 
Safely and without reader tricks:
<langsyntaxhighlight lang=clojure>(let [ints (map #(Integer/parseInt %) (clojure.string/split (read-line) #"\s") )]
(println (reduce + ints)))
3 4
=>7</langsyntaxhighlight>
 
or same as above, but without "let":
<langsyntaxhighlight lang=clojure>(println (reduce + (map #(Integer/parseInt %) (clojure.string/split (read-line) #"\s") )))
 
3 4
=>7</langsyntaxhighlight>
 
=={{header|COBOL}}==
<langsyntaxhighlight lang=cobol> IDENTIFICATION DIVISION.
PROGRAM-ID. A-Plus-B.
 
Line 1,896:
 
GOBACK
.</langsyntaxhighlight>
 
A second version.
 
<langsyntaxhighlight lang=COBOL>
 
IDENTIFICATION DIVISION.
Line 1,941:
STOP RUN.
 
</syntaxhighlight>
</lang>
 
=={{header|CoffeeScript}}==
{{trans|JavaScript}}
<langsyntaxhighlight 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,958:
<div id='output'></div>
</body>
</html></langsyntaxhighlight>
 
{{works with|Node.js}}
<langsyntaxhighlight lang=coffeescript>
{ stdin } = process
sum = ( a, b ) -> a + b
Line 1,992:
# Start the main loop.
do prompt
</syntaxhighlight>
</lang>
 
=={{header|Common Lisp}}==
<langsyntaxhighlight lang=lisp>(write (+ (read) (read)))</langsyntaxhighlight>
 
=={{header|Component Pascal}}==
BlackBox Component Builder
<langsyntaxhighlight lang=oberon2>
MODULE AB;
IMPORT StdLog, DevCommanders,TextMappers;
Line 2,029:
END Go;
END AB.
</syntaxhighlight>
</lang>
Execute: <i>AB.Go 12 23 ~ </i><br/>
{{out}}
Line 2,037:
 
=={{header|Computer/zero Assembly}}==
<langsyntaxhighlight lang=czasm> STP ; wait for input
a: 0
b: 0
LDA a
ADD b
STP</langsyntaxhighlight>
 
=={{header|Crystal}}==
<langsyntaxhighlight lang=ruby>puts gets.not_nil!.split.map(&.to_i).sum</langsyntaxhighlight>
 
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:
To handle the <code>nil</code> case we could do:
 
<langsyntaxhighlight lang=ruby>if line = gets
puts line.split.map(&.to_i).sum
else
puts "No input"
end</langsyntaxhighlight>
 
=={{header|D}}==
===From Console===
<langsyntaxhighlight lang=d>import std.stdio, std.conv, std.string;
 
void main() {
Line 2,070:
 
writeln(to!int(r[0]) + to!int(r[1]));
}</langsyntaxhighlight>
{{out}}
<pre>30</pre>
===From File===
<langsyntaxhighlight lang=d>void main() {
import std.stdio, std.file;
 
immutable ab = "sum_input.txt".slurp!(int, int)("%d %d")[0];
"sum_output.txt".File("w").writeln(ab[0] + ab[1]);
}</langsyntaxhighlight>
 
=={{header|Dart}}==
<langsyntaxhighlight lang=Dart>import 'dart:io';
 
// a little helper function that checks if the string only contains
Line 2,109:
}
}
</syntaxhighlight>
</lang>
 
{{out}}
Line 2,118:
 
=={{header|dc}}==
<syntaxhighlight lang =dc>? + psz</langsyntaxhighlight>
 
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}}==
<langsyntaxhighlight lang=DCL>$ read sys$command line
$ a = f$element( 0, " ", line )
$ b = f$element( 1, " ", line )
$ write sys$output a, "+", b, "=", a + b</langsyntaxhighlight>
 
=={{header|Delphi}}==
Console version.
<langsyntaxhighlight lang=delphi>program SUM;
 
{$APPTYPE CONSOLE}
Line 2,144:
Readln(s2);
Writeln(StrToIntDef(s1, 0) + StrToIntDef(s2,0));
end.</langsyntaxhighlight>
 
=={{header|Diego}}==
<langsyntaxhighlight lang=diego>set_namespace(rosettacode)_me();
begin_instuct(A + B);
Line 2,161:
exec_instruct(A + B)_me();
 
reset_namespace[];</langsyntaxhighlight>
 
=={{header|DMS}}==
<langsyntaxhighlight lang=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" )</langsyntaxhighlight>
 
=={{header|Dragon}}==
<langsyntaxhighlight lang=dragon>
select "graphic"
select "types"
Line 2,177:
 
showln a + b
</syntaxhighlight>
</lang>
 
=={{header|DWScript}}==
Ghetto GUI version
<langsyntaxhighlight 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));</langsyntaxhighlight>
 
=={{header|Déjà Vu}}==
{{trans|Python}}
===Console===
<langsyntaxhighlight lang=dejavu>0
for k in split !prompt "" " ":
+ to-num k
!print</langsyntaxhighlight>
 
=={{header|EasyLang}}==
Line 2,201:
b = number substr a$ i -1
print a + b
</syntaxhighlight>
</lang>
 
=={{header|EchoLisp}}==
<langsyntaxhighlight lang=scheme>
(+ (read-number 1 "value for A") (read-number 2 "value for B"))
</syntaxhighlight>
</lang>
 
=={{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.
<langsyntaxhighlight lang=edsac>[ A plus B
========
Line 2,242:
[ When loading is finished: ]
 
EZPF [ Branch to load point ]</langsyntaxhighlight>
{{out}}
<pre>00000000001000001</pre>
Line 2,260:
 
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.
<langsyntaxhighlight lang=edsac>
[A + B for Rosetta Code.
Read two integers and find their sum.
Line 2,369:
P F
-987.123.
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,379:
=={{header|EGL}}==
 
<langsyntaxhighlight lang=EGL>
package programs;
 
Line 2,398:
end
end
</syntaxhighlight>
</lang>
 
=={{header|Eiffel}}==
argument(0) contains the path of the executable - thus we start at argument(1)
<langsyntaxhighlight lang=eiffel>
class
APPLICATION
Line 2,416:
end
end
</syntaxhighlight>
</lang>
 
Alternatively ...
<langsyntaxhighlight lang=eiffel>
make
-- Run application.
Line 2,440:
end
end
</syntaxhighlight>
</lang>
 
=={{header|Ela}}==
<langsyntaxhighlight lang=ela>open monad io string list
 
a'b() = do
Line 2,449:
putStrLn <| show <| sum <| map gread <| string.split " " <| str
 
a'b() ::: IO</langsyntaxhighlight>
 
{{Out}}
Line 2,457:
=={{header|Elena}}==
ELENA 5.0 :
<langsyntaxhighlight lang=elena>import extensions;
public program()
Line 2,465:
console.loadLine(A,B).printLine(A + B)
}</langsyntaxhighlight>
 
Or more generic solution:
<langsyntaxhighlight lang=elena>import system'routines;
import extensions;
 
Line 2,477:
.selectBy(mssgconst toInt<convertorOp>[1])
.summarize())
}</langsyntaxhighlight>
 
=={{header|Elixir}}==
<langsyntaxhighlight lang=Elixir>IO.gets("Enter two numbers seperated by a space: ")
|> String.split
|> Enum.map(&String.to_integer(&1))
|> Enum.sum
|> IO.puts</langsyntaxhighlight>
 
=={{header|Elm}}==
<langsyntaxhighlight lang=Elm>
--To write this function directly run cmd
--Type elm-repl to start
Line 2,499:
--END
 
</syntaxhighlight>
</lang>
 
=={{header|Emacs Lisp}}==
<langsyntaxhighlight 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)))</langsyntaxhighlight>
 
=={{header|Emojicode}}==
<langsyntaxhighlight lang=Emojicode>🏁🍇
🆕🔡▶️👂🏼❗️ ➡️ input 💭 Get numbers as input string
🔫 input 🔤 🔤❗ ➡️ nums 💭 Split numbers by space
Line 2,515:
🍺🔢 🐽 nums 1❗ 10❗ ➡️ B 💭 Retrieve second number
😀 🔤🧲A➕B🧲🔤 ❗ 💭 Output sum
🍉️</langsyntaxhighlight>
 
=={{header|Erlang}}==
<langsyntaxhighlight lang=erlang>-module(aplusb).
-export([start/0]).
 
Line 2,527:
io:format("~w~n",[A+B]),
start()
end.</langsyntaxhighlight>
 
=={{header|ERRE}}==
<langsyntaxhighlight lang=ERRE>
PROGRAM SUM2
 
Line 2,543:
 
END PROGRAM
</syntaxhighlight>
</lang>
 
=={{header|Euler Math Toolbox}}==
 
<langsyntaxhighlight lang=Euler Math Toolbox>
>s=lineinput("Two numbers seperated by a blank");
Two numbers seperated by a blank? >4 5
Line 2,555:
>vs[1]()+vs[2]()
9
</syntaxhighlight>
</lang>
 
=={{header|Euphoria}}==
<langsyntaxhighlight lang=euphoria>include get.e
 
function snd(sequence s)
Line 2,569:
b = snd(get(0))
 
printf(1," %d\n",a+b)</langsyntaxhighlight>
 
=={{header|Excel}}==
Take any 3 columns of any row or rows. Let's say A1,B1 and C1 are taken. In C1 type in :
 
<langsyntaxhighlight lang=excel>
=A1+B1
</syntaxhighlight>
</lang>
 
The value of C1 will change as the values of A1 and B1 are changed
 
<lang>1 2 3
</syntaxhighlight>
</lang>
 
=={{header|F Sharp|F#}}==
<langsyntaxhighlight lang=fsharp>open System
 
let SumOf(str : string) =
Line 2,592:
let main argv =
Console.WriteLine(SumOf(Console.ReadLine()))
0</langsyntaxhighlight>
 
=={{header|Factor}}==
<langsyntaxhighlight lang=factor>USING: math.parser splitting ;
: a+b ( -- )
readln " " split1
[ string>number ] bi@ +
number>string print ;</langsyntaxhighlight>
<pre>
( scratchpad ) a+b
Line 2,607:
 
=={{header|FALSE}}==
<langsyntaxhighlight lang=false>[0[^$$'9>'0@>|~]['0-\10*+]#%]n: {read an integer}
n;!n;!+.</langsyntaxhighlight>
 
=={{header|Fantom}}==
<langsyntaxhighlight lang=fantom>class APlusB
{
public static Void main ()
Line 2,621:
echo (sum)
}
}</langsyntaxhighlight>
 
=={{header|FBSL}}==
Using stdin and stdout
<langsyntaxhighlight lang=qbasic>#APPTYPE CONSOLE
 
DIM %a, %b
Line 2,631:
PRINT a, "+", b, "=", a + b
 
PAUSE</langsyntaxhighlight>
 
=={{header|Fhidwfe}}==
<langsyntaxhighlight lang=Fhidwfe>
function listint scanint (num:ptr) {// as of writing, fhidwfe has no builtin int scanning
reset negative
Line 2,676:
puti$ + access_word$ inp 0u access_word$ inp 1u
free$ inp
</syntaxhighlight>
</lang>
 
=={{header|Fish}}==
<langsyntaxhighlight lang=Fish>i:o:"-"=?v1$68*-v
v >~01-0 >
>i:o:" "=?v68*-$a*+
Line 2,685:
v >~01-0 >
>i:o:d=?v68*-$a*+
>~*+aonao;</langsyntaxhighlight>
 
=={{header|Forth}}==
<langsyntaxhighlight lang=Forth>pad dup 80 accept evaluate + .</langsyntaxhighlight>
 
=={{header|Fortran}}==
<langsyntaxhighlight lang=fortran>program a_plus_b
implicit none
integer :: a,b
read (*, *) a, b
write (*, '(i0)') a + b
end program a_plus_b</langsyntaxhighlight>
And in Fortran 77
<langsyntaxhighlight lang=fortran> READ (1,100) I,J
100 FORMAT(2I5)
WRITE (2,200) I+J
200 FORMAT(1X,I5)
END</langsyntaxhighlight>
 
=={{header|Free Pascal}}==
<langsyntaxhighlight lang=pascal>program SUMA;
uses
SysUtils;
Line 2,715:
WriteLn(IntToStr(s1 + s2));
end.
</syntaxhighlight>
</lang>
 
 
=={{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.)
<langsyntaxhighlight lang=frink>
sum[eval[split[%r/\s+/, input[""]]]]
</syntaxhighlight>
</lang>
 
=={{header|FunL}}==
<langsyntaxhighlight lang=funl>println( sum(map(int, readLine().split(' +'))) )</langsyntaxhighlight>
 
=={{header|Furor}}==
<langsyntaxhighlight lang=Furor>
cin sto mystring
#s dec mystring @mystring sprintnl
Line 2,746:
{ „mylist” }
{ „nums” }
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,775:
=={{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.
<langsyntaxhighlight lang=futurebasic>
_window = 1
begin enum 1
Line 2,818:
 
HandleEvents
</syntaxhighlight>
</lang>
{{output}}
<pre>
Line 2,829:
 
=={{header|Gambas}}==
<langsyntaxhighlight lang=gambas>Public Sub Main()
Dim sInput As String = InputBox("Input 2 numbers seperated by a space", "A + B")
 
Print Split(sInput, " ")[0] & " + " & Split(sInput, " ")[1] & " = " & Str(Val(Split(sInput, " ")[0]) + Val(Split(sInput, " ")[1]))
 
End</langsyntaxhighlight>
Output:
<pre>
Line 2,842:
=={{header|Gastona}}==
Taking A and B from command line arguments
<langsyntaxhighlight lang=gastona>#listix#
 
<main>
"@<p1> + @<p2> = "
=, p1 + p2
</syntaxhighlight>
</lang>
Using Graphical interface
<langsyntaxhighlight lang=gastona>#javaj#
 
<layout of main>
Line 2,864:
<suma> =, eA + eB
</syntaxhighlight>
</lang>
 
=={{header|Gema}}==
<langsyntaxhighlight lang=gema><D> <D>=@add{$1;$2}</langsyntaxhighlight>
 
=={{header|Genie}}==
<langsyntaxhighlight lang=genie>[indent=4]
/*
A+B in Genie
Line 2,892:
print "B" + warning
 
print "From %s\nA + B = %llu", line, a+b</langsyntaxhighlight>
 
{{out}}
Line 2,912:
 
=={{header|GML}}==
<langsyntaxhighlight lang=GML>var add, a, b;
add = argument0; // get the string with the numbers to add
a = real(string_copy(add, 1, string_pos(" ", add)));
b = real(string_copy(add, string_pos(" ", add) + 1, string_length(add) - string_pos(" ", add)));
return(a + b);</langsyntaxhighlight>
 
=={{header|Go}}==
<langsyntaxhighlight lang=go>package main
 
import "fmt"
Line 2,927:
fmt.Scan(&a, &b)
fmt.Println(a + b)
}</langsyntaxhighlight>
 
=={{header|Golfscript}}==
<syntaxhighlight lang =golfscript>~+</langsyntaxhighlight>
 
=={{header|Golo}}==
<langsyntaxhighlight lang=Golo>#!/usr/bin/env golosh
----
This module asks for two numbers, adds them, and prints the result.
Line 2,959:
println("they both need to be numbers for this to work")
}
}</langsyntaxhighlight>
 
=={{header|Gosu}}==
<langsyntaxhighlight lang=Gosu>
uses java.io.InputStreamReader
uses java.util.Scanner
Line 2,972:
 
print( a + b )
</syntaxhighlight>
</lang>
 
=={{header|Groovy}}==
<langsyntaxhighlight lang=groovy>def abAdder = {
def reader = new Scanner(System.in)
def a = reader.nextInt();
Line 2,982:
a + b
}
abAdder()</langsyntaxhighlight>
 
=={{header|GUISS}}==
We cannot use variables, but we can find the sum of two numbers.Here we add 3 + 2:
<langsyntaxhighlight lang=guiss>Start,Programs,Accessories,Calculator,Button:3,Button:[plus],
Button:2,Button:[equals]</langsyntaxhighlight>
 
=={{header|Harbour}}==
<langsyntaxhighlight lang=visualfoxpro>PROCEDURE Main()
LOCAL GetList := {}
LOCAL bValid := { |n| iif(n>-1001, iif(n<1001, .T.,.F.),.F.) }
Line 3,003:
 
RETURN
</langsyntaxhighlight>
Screen output:<p>Enter two numbers (range -1000...+1000): ''-56 98''</p>
<p>Sum of given numbers is 42</p>
Line 3,009:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang=haskell>main = print . sum . map read . words =<< getLine</langsyntaxhighlight>
 
=={{header|hexiscript}}==
<langsyntaxhighlight lang=hexiscript>fun split s delim
let ret dict 32
let l len s
Line 3,032:
let a tonum nums[0]
let b tonum nums[1]
println a + b</langsyntaxhighlight>
 
=={{header|HicEst}}==
A and B are input via edit controls with spinners limiting inputs to +-1000.
<langsyntaxhighlight lang=HicEst>DLG(Edit=A, DNum, MIn=-1000, MAx=1000, E=B, DN, MI=-1000, MA=1000)
WRITE(Messagebox, Name) A, B, "Sum = ", A+B</langsyntaxhighlight>
 
=={{header|Hoon}}==
<lang>
|= [a=@ud b=@ud] (add a b)
</syntaxhighlight>
</lang>
 
=={{header|Hope}}==
Line 3,060:
 
=={{header|Huginn}}==
<langsyntaxhighlight lang=huginn>import Algorithms as algo;
import Text as text;
 
Line 3,075:
);
);
}</langsyntaxhighlight>
 
=={{header|Hy}}==
<langsyntaxhighlight lang=hy>(print (sum (map int (.split (input)))))</langsyntaxhighlight>
Alternatively, with the "threading tail" macro:
<langsyntaxhighlight lang=hy>(->> (input) (.split) (map int) (sum) (print))</langsyntaxhighlight>
 
=={{header|i}}==
<langsyntaxhighlight lang=i>main: print(integer(in(' '))+integer(in('\n'))); ignore</langsyntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
<langsyntaxhighlight lang=icon>procedure main()
numChars := '-'++&digits
read() ? {
Line 3,093:
}
write((\A + \B) | "Bad input")
end</langsyntaxhighlight>
 
=={{header|Idris}}==
<langsyntaxhighlight lang=idris>main : IO()
main = do
line <- getLine
print $ sum $ map cast $ words line</langsyntaxhighlight>
 
=={{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:
<langsyntaxhighlight lang=J> 2+3
5</langsyntaxhighlight>
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>.
<langsyntaxhighlight lang=J>+/". (1!:1(3))-.LF</langsyntaxhighlight>
2) Here's a little script, called "a+b.ijs":
<langsyntaxhighlight lang=J>#!/Applications/j602/bin/jconsole
echo +/". (1!:1(3))-.LF
exit ''</langsyntaxhighlight>
3) Here is an execution of the script:
<langsyntaxhighlight lang=bash>echo 2 3 | ./a+b.ijs
5</langsyntaxhighlight>
 
=={{header|Java}}==
<langsyntaxhighlight lang=java>import java.util.Scanner;
 
public class Sum2 {
Line 3,125:
System.out.println(in.nextInt() + in.nextInt()); // Standard output
}
}</langsyntaxhighlight>
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.
<langsyntaxhighlight lang=java>import java.io.*;
import java.util.*;
 
Line 3,153:
out.println(nextInt() + nextInt());
}
}</langsyntaxhighlight>
 
The following code uses a StreamTokenizer instead of a Scanner.
 
<langsyntaxhighlight lang=java>import java.io.*;
import java.nio.charset.Charset;
 
Line 3,173:
}
}
</syntaxhighlight>
</lang>
 
 
Line 3,191:
NEWLINE : WS* '\r'? '\n'
;
</syntaxhighlight>
</lang>
Produces:
<pre>
Line 3,212:
Client side:
 
<langsyntaxhighlight lang=html4strict><html>
<body>
<div id='input'></div>
Line 3,225:
</script>
</body>
</html></langsyntaxhighlight>
 
Server side (with [http://nodejs.org node.js]):
 
<langsyntaxhighlight lang=javascript>process.openStdin().on (
'data',
function (line) {
Line 3,238:
process.exit()
}
)</langsyntaxhighlight>
 
$ node io.js
Line 3,249:
=== ES6 ===
Node.js in a terminal:
<langsyntaxhighlight lang=javascript>process.stdin.on("data", buffer => {
console.log(
(buffer + "").trim().split(" ").map(Number).reduce((a, v) => a + v, 0)
);
});
</syntaxhighlight>
</lang>
 
<pre> $ node io.js
Line 3,262:
 
=== JScript Windows Script Host Version 5.8 ===
<langsyntaxhighlight lang=javascript>var a = WScript.StdIn.ReadLine();
var b = WScript.StdIn.ReadLine();
WSH.echo(a, " + " , b , " = " , Number(a)+Number(b));
</syntaxhighlight>
</lang>
 
=={{header|Joy}}==
===Console===
<syntaxhighlight lang =Joy>get get +.</langsyntaxhighlight>
===File===
<langsyntaxhighlight lang=Joy>"input.txt" include
"output.txt" "w" fopen
get get + fput pop quit.</langsyntaxhighlight>
 
=={{header|jq}}==
Since the given task is simply to add two numbers, the simplest approach in jq is illustrated by the following transcript:
<langsyntaxhighlight lang=jq>$ jq -s add
3 2
5 </langsyntaxhighlight>
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:<langsyntaxhighlight lang=jq>
def addpairs:
if length < 2 then empty
Line 3,286:
end;
 
addpairs</langsyntaxhighlight>
For example, here is a transcript that assumes the program is in a file named AB.jq:<langsyntaxhighlight lang=jq>
$ jq -s -f AB.jq
1 2 3 4 5 6
3
7
11</langsyntaxhighlight>
 
=={{header|Jsish}}==
<langsyntaxhighlight lang=javascript>/* A+B in Jsish */
var line = console.input();
var nums = line.match(/^\s*([+-]?[0-9]+)\s+([+-]?[0-9]+)\s*/);
Line 3,308:
} else {
puts("error: A+B requires two numbers separated by space");
}</langsyntaxhighlight>
 
{{out}}
Line 3,326:
=={{header|Julia}}==
Run from the command line:
<langsyntaxhighlight lang=julia>input = parse.(Int, split(readline(stdin)))
println(stdout, sum(input))</langsyntaxhighlight>
 
{{out}}
Line 3,335:
 
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.
<langsyntaxhighlight lang=Julia>julia> println(parse(Int, readuntil(stdin, ' ')) + parse(Int, readuntil(stdin, '\n')))
1 2
3</langsyntaxhighlight>
 
=={{header|K}}==
<syntaxhighlight lang=K>
<lang K>
split:{(a@&~&/' y=/: a:(0,&x=y)_ x) _dv\: y}
ab:{+/0$split[0:`;" "]}
Line 3,346:
2 3
5
</syntaxhighlight>
</lang>
 
=={{header|Keg}}==
<syntaxhighlight lang =Keg>+.</langsyntaxhighlight>
[https://tio.run/##y05N//9fW@//f1MDLjMDAA Try it online!]
 
Or, using flags (<code>-hr</code>):
<syntaxhighlight lang =Keg>+</langsyntaxhighlight>
[https://tio.run/##y05N//9f@/9/UwMuM4P/uhlFAA Try it online!]
 
=={{header|Kite}}==
<langsyntaxhighlight lang=Kite>#!/usr/bin/kite
 
import "System.file";
Line 3,369:
 
line = in|readline;
];</langsyntaxhighlight>
{{Out}}
<pre>
Line 3,379:
 
=={{header|Klong}}==
<syntaxhighlight lang=K>
<lang K>
{(1:$(*x?0c )#x)+1:$(1+*|x?0c )_x}@.rl()
2 3
5
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang=scala>// version 1.0.5-2
 
fun main(args: Array<String>) {
Line 3,408:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 3,422:
 
=={{header|KQL}}==
<langsyntaxhighlight lang=KQL>datatable(Input:string)[
'2 2',
'3 2'
]
| parse Input with A:int ' ' B:int
| project Input, Output = A + B</langsyntaxhighlight>
 
=={{header|L++}}==
<langsyntaxhighlight lang=lisp>(main
(decl int a)
(decl int b)
(>> std::cin a b)
(prn (+ a b)))</langsyntaxhighlight>
 
=={{header|Lambdatalk}}==
<langsyntaxhighlight lang=scheme>
Lambdatalk works in a wiki, lambdatank.
 
Line 3,469:
Several boxes can be created in the wiki page
with any valid lambdatalk expressions.
</syntaxhighlight>
</lang>
 
=={{header|Lang5}}==
<langsyntaxhighlight lang=lang5>read read + .
 
read " " split expand drop + .</langsyntaxhighlight>
 
=={{header|Lasso}}==
<syntaxhighlight lang =lb>[a + b]</langsyntaxhighlight>
 
=={{header|LIL}}==
<langsyntaxhighlight lang=tcl># A+B, in LIL
# Requires lil shell readline routine
set in [readline]
Line 3,487:
if [expr $A < -1000 || $A > 1000] { print "A out of range: $A"; exit 1 }
if [expr $B < -1000 || $B > 1000] { print "B out of range: $B"; exit 1 }
print [expr $A + $B]</langsyntaxhighlight>
 
{{out}}
Line 3,494:
 
=={{header|Lisaac}}==
<langsyntaxhighlight lang=lisaac>Section Header
+ name := A_PLUS_B
 
Section Public
- main <- ( (IO.read_integer; IO.last_integer) +
(IO.read_integer; IO.last_integer) ).println;</langsyntaxhighlight>
 
=={{header|Little}}==
<langsyntaxhighlight lang=c>void main() {
string a, b;
scan(gets(stdin), "%d %d", &a, &b);
puts(((int)a + (int)b));
}</langsyntaxhighlight>
 
=={{header|Little Man Computer}}==
Line 3,514:
 
'''Assembly'''
<langsyntaxhighlight lang=Little Man Computer> INP
STA 99
INP
Line 3,520:
OUT
HLT
// Output the sum of two numbers</langsyntaxhighlight>
 
'''Machine code'''
<langsyntaxhighlight lang=Little Man Computer>00 INP
01 STA 99
02 INP
03 ADD 99
04 OUT
05 HLT</langsyntaxhighlight>
 
=={{header|LiveCode}}==
Using Livecode Server script
<langsyntaxhighlight lang=LiveCode><?lc
if isNumber($0) and isNumber($1) then
put $0 + $1
Line 3,538:
put $0 && $1
end if
?></langsyntaxhighlight>
 
A graphical version using an input dialog
<langsyntaxhighlight lang=LiveCode>on mouseUp
ask "Enter two numbers"
set itemdelimiter to space
Line 3,550:
answer item 1 of nums && item 2 of nums
end if
end mouseUp</langsyntaxhighlight>
 
=={{header|Logo}}==
<syntaxhighlight lang =logo>show apply "sum readlist</langsyntaxhighlight>
 
=={{header|Lua}}==
<langsyntaxhighlight lang=Lua>a,b = io.read("*number", "*number")
print(a+b)</langsyntaxhighlight>
 
=={{header|M2000 Interpreter}}==
Line 3,564:
Input A%, B%
} Until Range(A%) And Range(B%)
Print A%+B%</langsyntaxhighlight>
 
=={{header|M4}}==
<langsyntaxhighlight lang=M4> define(`sumstr', `eval(patsubst(`$1',` ',`+'))')
 
sumstr(1 2)
3</langsyntaxhighlight>
 
=={{header|Maple}}==
<langsyntaxhighlight lang=maple> convert( scanf( "%d %d" ), '`+`' );
23 34
57</langsyntaxhighlight>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
Interactive in a notebook
<syntaxhighlight lang =Mathematica>Input[] + Input[]</langsyntaxhighlight>
 
=={{header|MATLAB}} / {{header|Octave}}==
<langsyntaxhighlight lang=MATLAB>function sumOfInputs = APlusB()
inputStream = input('Enter two numbers, separated by a space: ', 's');
numbers = str2num(inputStream); %#ok<ST2NM>
Line 3,589:
end
sumOfInputs = sum(numbers);
end</langsyntaxhighlight>
 
=={{header|Maude}}==
===Built-in===
<langsyntaxhighlight lang=Maude>
red 3 + 4 .
</syntaxhighlight>
</lang>
===With restrictions===
<langsyntaxhighlight lang=Maude>
fmod ADD is
 
Line 3,610:
endfm
</syntaxhighlight>
</lang>
 
=={{header|Maxima}}==
Line 3,619:
);
close(in_stream);
</syntaxhighlight>
</lang>
 
=={{header|Mercury}}==
Line 3,641:
else
true
).</langsyntaxhighlight>
 
=={{header|min}}==
{{works with|min|0.19.3}}
<langsyntaxhighlight lang=min>gets " " split 'bool filter 'int map sum puts!</langsyntaxhighlight>
 
=={{header|MiniScript}}==
The <code>input</code> intrinsic in MiniScript isn't available in all implementations, so we've just hard-coded the input here:
<langsyntaxhighlight lang=MiniScript>s = " 2 3 "
fields = s.split
for i in range(fields.len-1, 0)
Line 3,658:
else
print val(fields[0]) + val(fields[1])
end if</langsyntaxhighlight>
 
{{out}}
Line 3,664:
 
=={{header|mIRC Scripting Language}}==
<langsyntaxhighlight lang=mirc>alias a+b {
echo -ag $calc($1 + $2)
}</langsyntaxhighlight>
 
=={{header|МК-61/52}}==
Line 3,675:
=={{header|ML/I}}==
The two numbers are read from 'standard input' or its equivalent.
<langsyntaxhighlight lang=ML/I>MCSKIP "WITH" NL
"" A+B
"" assumes macros on input stream 1, terminal on stream 2
Line 3,687:
MCSKIP SL WITH *
MCSET S1=1
*MCSET S10=2</langsyntaxhighlight>
 
=={{header|Modula-2}}==
<langsyntaxhighlight lang=modula2>MODULE ab;
 
IMPORT InOut;
Line 3,701:
InOut.WriteInt (A + B, 8);
InOut.WriteLn
END ab.</langsyntaxhighlight>
 
=={{header|Modula-3}}==
<langsyntaxhighlight lang=modula3>MODULE Ab EXPORTS Main;
 
IMPORT IO;
Line 3,719:
IO.PutInt(A+B);
IO.Put("\n");
END Ab.</langsyntaxhighlight>
 
=={{header|MoonScript}}==
<langsyntaxhighlight lang=moonscript>a,b = io.read '*number','*number'
print a + b</langsyntaxhighlight>
 
=={{header|MUMPS}}==
<langsyntaxhighlight lang=MUMPS>ANB
NEW A,B,T,S
READ !,"Input two integers between -1000 and 1000, separated by a space: ",S
Line 3,733:
IF T WRITE !,(A+B)
IF 'T WRITE !,"Bad input"
QUIT</langsyntaxhighlight>
 
=={{header|Nanoquery}}==
<langsyntaxhighlight lang=Nanoquery>// get a line of input
line = input()
Line 3,743:
// add the two numbers and print the result
println int(strings[0]) + int(strings[1])</langsyntaxhighlight>
 
=={{header|Neko}}==
<langsyntaxhighlight lang=ActionScript>/**
A+B, Rosetta Code, in Neko
Tectonics:
Line 3,810:
} else $print("Need two numbers, separated by whitespace\n")
 
} catch with $print("Exception: ", with, "\n")</langsyntaxhighlight>
 
{{out}}
Line 3,822:
=={{header|Nemerle}}==
{{trans|C#}}
<langsyntaxhighlight lang=Nemerle>using System;
using System.Console;
using System.Linq;
Line 3,832:
WriteLine(ReadLine().Split().Select(int.Parse).Sum());
}
}</langsyntaxhighlight>
 
=={{header|NetRexx}}==
<langsyntaxhighlight lang=NetRexx>/* NetRexx */
 
options replace format comments java symbols binary
 
parse ask a b .
say a '+' b '=' a + b</langsyntaxhighlight>
 
=={{header|newLISP}}==
<langsyntaxhighlight lang=newLISP>(println (apply + (map int (parse (read-line)))))</langsyntaxhighlight>
 
=={{header|Nim}}==
A+B:
<langsyntaxhighlight lang=nim>
# Takes 2 inputs of Floats and adds them (which is not correct for the exercise, will revisit, Thank you
 
Line 3,868:
let second: float = getnumber()
 
echo("Result: " & formatFloat(aplusb(first, second), ffDecimal, 2))</langsyntaxhighlight>
 
The puzzle requires 1 input, 2 INTS separated by a space, than a+b
Line 3,875:
=={{header|Nit}}==
Generic non-robust version (source: [https://github.com/nitlang/nit/blob/master/examples/rosettacode/ab.nit the Nit’s official repository]):
<langsyntaxhighlight lang=nit>module ab
 
var words = gets.split(" ")
Line 3,882:
return
end
print words[0].to_i + words[1].to_i</langsyntaxhighlight>
 
=={{header|NS-HUBASIC}}==
<langsyntaxhighlight lang=NS-HUBASIC>10 INPUT "ENTER NUMBER A: ",A
20 INPUT "ENTER NUMBER B: ",B
30 PRINT A+B</langsyntaxhighlight>
 
=={{header|Nyquist}}==
===SAL Syntax===
<langsyntaxhighlight lang=Nyquist>;nyquist plug-in
;version 1
;type tool
Line 3,902:
print a + b
return ""</langsyntaxhighlight>
 
===Audacity plug-in (SAL syntax)===
<langsyntaxhighlight lang=Nyquist>;nyquist plug-in
;version 1
;type tool
Line 3,916:
print a + b
 
return ""</langsyntaxhighlight>
 
=={{header|Oberon-2}}==
<langsyntaxhighlight lang=oberon2>MODULE ab;
 
IMPORT In, Out;
Line 3,930:
Out.Int (A + B, 8);
Out.Ln
END ab.</langsyntaxhighlight>
Producing
<pre>
Line 3,938:
 
=={{header|Objeck}}==
<langsyntaxhighlight lang=objeck>bundle Default {
class Vander {
function : Main(args : String[]) ~ Nil {
Line 3,947:
}
}
}</langsyntaxhighlight>
 
=={{header|OCaml}}==
<langsyntaxhighlight lang=ocaml>Scanf.scanf "%d %d" (fun a b -> Printf.printf "%d\n" (a + b))</langsyntaxhighlight>
 
=={{header|Oforth}}==
Line 3,956:
Works with any number of integers separated by a space.
 
<langsyntaxhighlight lang=Oforth>import: mapping
 
System.Console accept words map( #>integer) reduce( #+ ) printcr .</langsyntaxhighlight>
 
=={{header|Ol}}==
Note: input data must be separated by newline ([Enter] key press).
 
<langsyntaxhighlight lang=ol>; simplest
(+ (read) (read))
 
Line 3,975:
 
(print a " + " b " = " (+ a b)))
</syntaxhighlight>
</lang>
 
=={{header|Onyx}}==
 
<langsyntaxhighlight lang=onyx>$Prompt {
`\nEnter two numbers between -1000 and +1000,\nseparated by a space: ' print flush
} def
Line 4,003:
} def
 
Prompt GetNumbers CheckInput Answer</langsyntaxhighlight>
 
=={{header|ooRexx}}==
===version 1===
{{trans|REXX}}
<langsyntaxhighlight 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,026:
Parse arg list
list=space(list)
return translate(list,'+',' ')</langsyntaxhighlight>
{{out}}
<pre>enter some numbers to be summed:
Line 4,032:
===version 2===
extend for negative numbers
<langsyntaxhighlight lang=oorexx>Numeric digits 1000
Say 'enter some numbers to be summed:'
parse pull y
Line 4,052:
End
Say yplus '=' sum/1
Exit</langsyntaxhighlight>
 
=={{header|OpenEdge/Progress}}==
<langsyntaxhighlight lang=progress>DEFINE VARIABLE a AS INTEGER NO-UNDO FORMAT "->>>9".
DEFINE VARIABLE b AS INTEGER NO-UNDO FORMAT "->>>9".
 
Line 4,066:
UPDATE a b.
 
MESSAGE a + b VIEW-AS ALERT-BOX</langsyntaxhighlight>
 
=={{header|Openscad}}==
There is no means of run-time input in Openscad
<langsyntaxhighlight lang=openscad>
a = 5 + 4;
echo (a);
</syntaxhighlight>
</lang>
 
=={{header|Order}}==
Line 4,079:
 
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))'''.
<langsyntaxhighlight lang=order>
#define ORDER_PP_DEF_1int_is_positive \
ORDER_PP_FN(8fn(8X, 8is_0(8tuple_at_0(8X))))
Line 4,116:
 
ORDER_PP(8int_to_lit(8int_add(A, B)))
</syntaxhighlight>
</lang>
 
=={{header|Oxygene}}==
<langsyntaxhighlight lang=oxygene>
// Sum 2 integers read fron standard input
//
Line 4,152:
end.
</syntaxhighlight>
</lang>
Produces:
<pre>
Line 4,161:
 
=={{header|Oz}}==
<langsyntaxhighlight lang=oz>declare
class TextFile from Open.file Open.text end
 
Line 4,170:
end
in
{Show {ReadInt}+{ReadInt}}</langsyntaxhighlight>
 
=={{header|PARI/GP}}==
User input:
<syntaxhighlight lang =parigp>input()+input()</langsyntaxhighlight>
File input:
<langsyntaxhighlight lang=parigp>read("file1")+read("file2")</langsyntaxhighlight>
 
=={{header|Pascal}}==
<langsyntaxhighlight lang=pascal>var
a, b: integer;
begin
readln(a, b);
writeln(a + b);
end.</langsyntaxhighlight>
Same with input from file <tt>input.txt</tt> and output from file <tt>output.txt</tt>.
<langsyntaxhighlight lang=pascal>var
a, b: integer;
begin
Line 4,195:
close(input);
close(output);
end.</langsyntaxhighlight>
===Version 2. Following the rules===
<langsyntaxhighlight lang=pascal>{ Task: A + B
Sum of A + B while A, B >= -1000 and A,B <= 1000
Author: Sinuhe Masan (2019) }
Line 4,214:
writeln('The sum is: ', A + B);
 
end.</langsyntaxhighlight>
 
=={{header|Perl}}==
<langsyntaxhighlight lang=Perl>my ($a,$b) = split(' ', scalar(<STDIN>));
print "$a $b " . ($a + $b) . "\n";</langsyntaxhighlight>
 
=== using the List::Util module ===
<langsyntaxhighlight lang=Perl>say sum split /\s+/, scalar <STDIN>;</langsyntaxhighlight>
 
=={{header|Phix}}==
<!--<langsyntaxhighlight lang=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,234:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"invalid input\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 4,242:
=== GUI version ===
<small>(The above console version is now just a comment in the distributed file.)</small>
<!--<langsyntaxhighlight lang=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,275:
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</langsyntaxhighlight>-->
 
=={{header|Phixmonti}}==
<langsyntaxhighlight lang=Phixmonti>/# Rosetta Code problem: http://rosettacode.org/wiki/A+B
by Galileo, 05/2022 #/
 
Line 4,294:
 
over over + >ps
nl "The sum of " print print " and " print print " is: " print ps> print</langsyntaxhighlight>
{{out}}
<pre>Enter two numbers (betwen -1000 ... +1000) separated by space: 2 3
Line 4,301:
 
=={{header|PHP}}==
<langsyntaxhighlight lang=php>fscanf(STDIN, "%d %d\n", $a, $b); //Reads 2 numbers from STDIN
echo ($a + $b) . "\n";</langsyntaxhighlight>
<langsyntaxhighlight lang=php>$in = fopen("input.dat", "r");
fscanf($in, "%d %d\n", $a, $b); //Reads 2 numbers from file $in
fclose($in);
Line 4,309:
$out = fopen("output.dat", "w");
fwrite($out, ($a + $b) . "\n");
fclose($out);</langsyntaxhighlight>
 
=={{header|Picat}}==
<langsyntaxhighlight lang=Picat>
go =>
println("Write two integers (and CR)"),
println(read_int()+read_int()).
</syntaxhighlight>
</lang>
 
{{out}}
Line 4,333:
 
=={{header|PicoLisp}}==
<langsyntaxhighlight lang=PicoLisp>(+ (read) (read))
3 4
-> 7</langsyntaxhighlight>
 
=={{header|Piet}}==
[[File:Piet A+B.png]]
The code is fairly straightforward. The individual commands are as follows:
<langsyntaxhighlight lang=text>in(num)
in(num)
add
out(num)</langsyntaxhighlight>
 
=={{header|Pike}}==
<langsyntaxhighlight lang=Pike>string line = Stdio.stdin->gets();
sscanf(line, "%d %d", int a, int b);
write(a+b +"\n");</langsyntaxhighlight>
 
=={{header|PL/I}}==
<langsyntaxhighlight lang=pli>get (a, b);
put (a+b);</langsyntaxhighlight>
 
=={{header|Pony}}==
<langsyntaxhighlight lang=pony>
actor Main
let _env:Env
Line 4,381:
_env.out.print(sum.string())
 
</syntaxhighlight>
</lang>
 
=={{header|PostScript}}==
<langsyntaxhighlight lang=postscript>(%stdin) (r) file % get stdin
dup
token pop % read A
Line 4,390:
token pop % read B
add
=</langsyntaxhighlight>
 
=={{header|Potion}}==
<langsyntaxhighlight 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,405:
 
# The numbers are manually inputted, but the format is improper (i.e., "%d\n%d\n").
(read number + read number) print</langsyntaxhighlight>
 
=={{header|PowerShell}}==
<langsyntaxhighlight lang=powershell>$a,$b = -split "$input"
[int]$a + [int]$b</langsyntaxhighlight>
This solution does not work interactively, while the following ''only'' works interactively:
<langsyntaxhighlight lang=powershell>$a,$b = -split (Read-Host)
[int]$a + [int]$b</langsyntaxhighlight>
 
I think this works better and doesn't require string input (following the task closer):
<langsyntaxhighlight lang=powershell>filter add {
return [int]$args[0] + [int]$args[1]
}</langsyntaxhighlight>
 
Can be called in one line with
<syntaxhighlight lang =powershell>add 2 3</langsyntaxhighlight>
 
=={{header|Processing}}==
===Rudimentary User Interface===
Click on either side to add 1 to its value.
<langsyntaxhighlight lang=Processing>int a = 0;
int b = 0;
 
Line 4,449:
b++;
}
}</langsyntaxhighlight>
 
[https://i.imgur.com/QEHtMyA.jpg What the GUI looks like.]
Line 4,455:
=={{header|ProDOS}}==
With the math module:
<langsyntaxhighlight lang=ProDOS>editvar /newvar /value=a /title=Enter an integer:
editvar /newvar /value=b /title=Enter another integer:
editvar /newvar /value=c
do add -a-,-b-=-c-
printline -c- </langsyntaxhighlight>
Without the math module:
<langsyntaxhighlight lang=ProDOS>editvar /newvar /value=a /title=Enter an integer:
editvar /newvar /value=b /title=Enter another integer:
editvar /newvar /value=c=-a-+-b-
printline -c- </langsyntaxhighlight>
 
=={{header|Prolog}}==
{{Works with|SWI-Prolog}}
<langsyntaxhighlight lang=Prolog>plus :-
read_line_to_codes(user_input,X),
atom_codes(A, X),
Line 4,474:
maplist(atom_number, L, LN),
sumlist(LN, N),
write(N).</langsyntaxhighlight>
output :
<langsyntaxhighlight lang=Prolog>?- plus.
|: 4 5
9
true.</langsyntaxhighlight>
 
=={{header|Pure}}==
<langsyntaxhighlight lang=pure>using system;
printf "%d\n" (x+y) when x,y = scanf "%d %d" end;</langsyntaxhighlight>
 
=={{header|PureBasic}}==
===Console===
<langsyntaxhighlight lang=PureBasic>x$=Input()
a=Val(StringField(x$,1," "))
b=Val(StringField(x$,2," "))
PrintN(str(a+b))</langsyntaxhighlight>
===File===
<langsyntaxhighlight lang=PureBasic>If ReadFile(0,"in.txt")
x$=ReadString(0)
a=Val(StringField(x$,1," "))
Line 4,501:
EndIf
CloseFile(0)
EndIf </langsyntaxhighlight>
 
=={{header|Python}}==
Line 4,510:
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.
 
<langsyntaxhighlight lang=python>try: raw_input
except: raw_input = input
 
print(sum(map(int, raw_input().split())))</langsyntaxhighlight>
 
===File===
For Python 2.X and 3.X taking input from stdin stream which can be redirected to be file input under Unix
<langsyntaxhighlight lang=python>import sys
 
for line in sys.stdin:
print(sum(map(int, line.split())))</langsyntaxhighlight>
 
===Console, Python 3 only===
<langsyntaxhighlight lang=python>a = int(input("First number: "))
b = int(input("Second number: "))
print("Result:", a+b)</langsyntaxhighlight>
 
=={{header|QB64}}==
<langsyntaxhighlight lang=QB64>DIM a AS INTEGER, b AS INTEGER
DIM c AS LONG
INPUT "Enter A: ", a
Line 4,534:
c = a + b
PRINT ""
PRINT "A + B = " + LTRIM$(STR$(c)) </langsyntaxhighlight>
 
'''Fully implemented version:'''
Line 4,544:
** Integers between -1000 and +1000.
<langsyntaxhighlight 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,558:
b$ = LTRIM$(STR$(b)) ' | "
sum$ = LTRIM$(STR$(a + b)) ' | "
PRINT "The sum of the two integers a + b = "; a$; " + "; b$; " = "; sum$</langsyntaxhighlight>
 
=={{header|Quackery}}==
Line 4,571:
 
=={{header|Quite BASIC}}==
<langsyntaxhighlight lang=Quite BASIC>10 input "Enter number A: ";a
20 input "Enter number B: ";b
30 print a+b</langsyntaxhighlight>
 
=={{header|R}}==
<langsyntaxhighlight lang=r>sum(scan("", numeric(0), 2))</langsyntaxhighlight>
 
=={{header|Ra}}==
<syntaxhighlight lang=Ra>
<lang Ra>
class Sum
**Adds two given integers**
Line 4,605:
print to Console.error made !, "Numbers too large"
exit program with error code
</syntaxhighlight>
</lang>
 
=={{header|Racket}}==
 
<langsyntaxhighlight lang=racket>
#lang racket
(+ (read) (read))
</syntaxhighlight>
</lang>
 
Or, with additional error checking:
<langsyntaxhighlight lang=racket>
#lang racket
(define a (read))
Line 4,622:
(unless (number? b) (error 'a+b "number" b))
(displayln (+ a b))
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
Line 4,629:
 
Short version with very little "line noise":
<syntaxhighlight lang =perl6>get.words.sum.say;</langsyntaxhighlight>
Reduction operator <code>[+]</code>, and <code>say</code> as a function:
<syntaxhighlight lang =perl6>say [+] get.words;</langsyntaxhighlight>
Long version:
<langsyntaxhighlight lang=perl6>my ($a, $b) = $*IN.get.split(" ");
say $a + $b;</langsyntaxhighlight>
 
=={{header|REBOL}}==
<langsyntaxhighlight lang=rebol>forever [x: load input print x/1 + x/2]</langsyntaxhighlight>
{{Out}}
<pre>1 2
Line 4,647:
 
=={{header|Red}}==
<langsyntaxhighlight lang=Red>x: load input print x/1 + x/2</langsyntaxhighlight>
{{Out}}
<pre>1 2
Line 4,657:
 
Alternative implementations:
<langsyntaxhighlight lang=Red>print (first x: load input) + x/2</langsyntaxhighlight>
<langsyntaxhighlight lang=Red>print head insert load input 'add</langsyntaxhighlight>
<langsyntaxhighlight lang=Red>print load replace input " " " + "</langsyntaxhighlight>
 
=={{header|Relation}}==
<langsyntaxhighlight lang=Relation>
set input = "2 2"
set a = regexreplace(input,"^(-?\d+)\s+(-?\d+)+$","$1")
set b = regexreplace(input,"^(-?\d+)\s+(-?\d+)+$","$2")
echo a + b
</syntaxhighlight>
</lang>
 
=={{header|Retro}}==
<langsyntaxhighlight lang=Retro>:try ("-n) s:get s:to-number s:get s:to-number + n:put ;</langsyntaxhighlight>
<langsyntaxhighlight lang=Retro>try
1
2</langsyntaxhighlight>
 
=={{header|REXX}}==
===version 1, unnormalized===
The numbers can be any valid REXX number (integer, fixed point decimal, floating point (with exponential notation, ···).
<langsyntaxhighlight 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. */
/*stick a fork in it, we're all done. */</langsyntaxhighlight>
===version 2, normalizied===
If the user entered &nbsp; '''4.00000''' &nbsp; and wanted to add &nbsp; '''5''' &nbsp; to that, and expects &nbsp; '''9''',
Line 4,690:
 
Dividing by one normalizes the number.
<langsyntaxhighlight 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. */
/*stick a fork in it, we're all done. */</langsyntaxhighlight>
 
===version 3, extended precision===
Using the &nbsp; '''numeric digits''' &nbsp; statement allows more decimal digits to be used, the default is &nbsp; '''9'''.
<langsyntaxhighlight 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.*/
z= (a+b) / 1 /*add and normalize sum, store it in Z.*/
say z /*display normalized sum Z to terminal.*/
/*stick a fork in it, we're all done. */</langsyntaxhighlight>
 
===version 4, multiple numbers===
This REXX version adds &nbsp; ''all'' &nbsp; the numbers entered &nbsp; (not just two).
<langsyntaxhighlight 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,716:
end /*j*/
/*stick a fork in it, we're all done. */
say 'sum of ' many " numbers = " $/1 /*display normalized sum $ to terminal.*/</langsyntaxhighlight>
 
===version 5, multiple numbers, tongue in cheek===
<langsyntaxhighlight 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,726:
y=translate(y,'+',' ')
Interpret 's='y
say 'sum of ' many " numbers = " s/1 /*display normalized sum s to terminal.*/</langsyntaxhighlight>
 
=={{header|Ring}}==
<langsyntaxhighlight lang=ring>give Numbers
Numbers = split(Numbers)
sum = 0
Line 4,737:
func Split Str
for x in str if x = " " x = nl ok next
return str2list(str)</langsyntaxhighlight>
 
=={{header|Robotic}}==
<langsyntaxhighlight lang=robotic>
input string "Input A:"
set "A" to "input"
Line 4,747:
* "('A' + 'B')"
end
</syntaxhighlight>
</lang>
 
Although the function in the first and third line asks for a string as the input, so long as the variable isn't made to store a string, it will default to an integer instead. Inserting a string to this will return a 0.
Line 4,753:
=={{header|Rockstar}}==
Minimized:
<langsyntaxhighlight lang=Rockstar>
Listen to A number
Listen to B
Say A number plus B
</syntaxhighlight>
</lang>
Idiomatic:
<langsyntaxhighlight lang=Rockstar>
Listen to my voice
Listen to your thoughts
Shout your thoughts with my voice
</syntaxhighlight>
</lang>
 
=={{header|Ruby}}==
<langsyntaxhighlight lang=ruby>puts gets.split.sum(&:to_i)</langsyntaxhighlight>
 
=={{header|Run BASIC}}==
<langsyntaxhighlight lang=runbasic>input, x$
print val(word$(x$,1)) + val(word$(x$,2))</langsyntaxhighlight>
 
=={{header|Rust}}==
<langsyntaxhighlight lang=rust>use std::io;
 
fn main() {
Line 4,784:
}
println!("{}", i);
}</langsyntaxhighlight>
 
or
 
<langsyntaxhighlight lang=rust>use std::io;
 
fn main() {
Line 4,798:
.sum();
println!("{}", sum);
}</langsyntaxhighlight>
 
=={{header|S-lang}}==
<langsyntaxhighlight lang=C>% A+B from stdin, sans error checking
variable input, a, b;
 
Line 4,807:
input = strtrim_end(input, "\n");
() = sscanf(input, "%d%d", &a, &b);
print(a + b);</langsyntaxhighlight>
 
{{out}}
Line 4,813:
46</pre>
 
<langsyntaxhighlight lang=C>% A+B from stdin, basic validity testing
variable input, a, b, rc;
 
Line 4,823:
} else {
message("input invalid or out of range (-1000,1000): $input"$);
}</langsyntaxhighlight>
 
=={{header|Scala}}==
<langsyntaxhighlight lang=scala>println(readLine().split(" ").map(_.toInt).sum)</langsyntaxhighlight>
 
This will work if the input is exactly as specified, with no extra whitespace. A slightly more robust version:
 
<langsyntaxhighlight lang=scala>val s = new java.util.Scanner(System.in)
val sum = s.nextInt() + s.nextInt()
println(sum)</langsyntaxhighlight>
 
or
 
<langsyntaxhighlight lang=scala>println(readLine().split(" ").filter(_.length>0).map(_.toInt).sum)</langsyntaxhighlight>
 
=={{header|Scheme}}==
<langsyntaxhighlight lang=scheme>(display (+ (read) (read)))</langsyntaxhighlight>
 
=={{header|Scratch}}==
Line 4,848:
=={{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.
<langsyntaxhighlight lang=sed>: Loop
# All done
/^-*00* /s///
Line 4,873:
# Decrement 2nd
s/\([^0]\)\(0*\);[^0]*\1\(.\).*\2\(9*\).*/\3\4/
t Loop</langsyntaxhighlight>
 
Another method, based off of [http://unix.stackexchange.com/a/36959/11750 this StackExchange answer]:
<langsyntaxhighlight lang=sed>#!/bin/sed -f
 
# Add a marker in front of each digit, for tracking tens, hundreds, etc.
Line 4,914:
s/</|/g
t back
s/^$/0/</langsyntaxhighlight>
 
=={{header|Seed7}}==
<langsyntaxhighlight lang=seed7>$ include "seed7_05.s7i";
 
const proc: main is func
Line 4,927:
read(b);
writeln(a + b);
end func;</langsyntaxhighlight>
 
=={{header|Self}}==
Works with positive and negative integers, and also more than two integers.
 
<langsyntaxhighlight lang=self>((stdin readLine splitOn: ' ') mapBy: [|:e| e asInteger]) sum printLine.</langsyntaxhighlight>
 
=={{header|SenseTalk}}==
<langsyntaxhighlight lang=sensetalk>ask "Enter the first number:"
put it into a
 
Line 4,941:
put it into b
 
put a + b</langsyntaxhighlight>
<langsyntaxhighlight lang=sensetalk>put file "input.txt" into inputFile
split inputFile by space
put sum of inputFile</langsyntaxhighlight>
 
=={{header|SequenceL}}==
<langsyntaxhighlight lang=sequencel>import <Utilities/Conversion.sl>;
 
main(args(2)) := stringToInt(args[1]) + stringToInt(args[2]);</langsyntaxhighlight>
 
{{Out}}
Line 4,962:
 
=={{header|SETL}}==
<langsyntaxhighlight lang=setl>read(A, B);
print(A + B);</langsyntaxhighlight>
 
=={{header|Shiny}}==
<langsyntaxhighlight lang=shiny>if (io.line 'stdin').match ~(\d+)\s+(\d+)~
say "$a $b %(a+b)d"
end</langsyntaxhighlight>
 
=={{header|Sidef}}==
Works with both positive and negative integers.
<langsyntaxhighlight lang=ruby>say STDIN.readline.words.map{.to_i}.sum</langsyntaxhighlight>
 
More idiomatically:
<langsyntaxhighlight lang=ruby>say read(String).words»to_i»()«+»</langsyntaxhighlight>
 
Explicit summation:
<langsyntaxhighlight lang=ruby>var (a, b) = read(String).words.map{.to_i}...
say a+b</langsyntaxhighlight>
 
=={{header|Simula}}==
<langsyntaxhighlight lang=simula>BEGIN
WHILE NOT LASTITEM DO
BEGIN
Line 4,989:
END;
END.
</syntaxhighlight>
</lang>
 
=={{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.
<langsyntaxhighlight 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,022:
test3Plus2
^ self
sum: (ReadStream on: '3 2')! !</langsyntaxhighlight>
 
but all have a stream hierarchy, so the task could be restated to pass input and output as stream arguments:
{{works with|Smalltalk/X}}
{{works with|VisualWorks Smalltalk}}
<langsyntaxhighlight lang=smalltalk>|task|
task := [:inStream :outStream |
|processLine|
Line 5,045:
].
 
task value: ( 'dataIn.txt' asFilename readStream) value:Transcript.</langsyntaxhighlight>
or:
<langsyntaxhighlight lang=smalltalk>task value: Stdin value: Stdout.</langsyntaxhighlight>
 
=={{header|smart BASIC}}==
<langsyntaxhighlight lang=qbasic>INPUT n$
PRINT VAL(LEFT$(n$,(LEN(STR$(VAL(n$))))))+VAL(RIGHT$(n$,(LEN(n$)-LEN(STR$(VAL(n$)))-1)))</langsyntaxhighlight>
 
<b>NOTE:</b> This is a horribly forced way of doing this. smart BASIC has commands to SPLIT strings. Surely someone can provide better code than what I've written here. ;@)
Line 5,059:
A FAR more elegant solution was provided by "Dutchman" on the smart [http://kibernetik.pro/forum/viewforum.php?f=2 BASIC Support Forum]:
 
<langsyntaxhighlight lang=qbasic>INPUT n$
SPLIT n$ TO m$,n WITH " "
PRINT m$(0),m$(1),m$(0)+m$(1)</langsyntaxhighlight>
 
<b>NOTE:</b> smart BASIC will intelligently interpret the contents of a string as a numeric value if necessary. Other versions of BASIC would require the values stored in a string to be converted to numeric values before calculation.
 
=={{header|SmileBASIC}}==
<langsyntaxhighlight lang=smilebasic>INPUT A
INPUT B
PRINT A+B
</syntaxhighlight>
</lang>
 
=={{header|SNOBOL4}}==
Simple-minded solution (literally "two somethings separated by space")
<langsyntaxhighlight lang=snobol> input break(" ") . a " " rem . b
output = a + b
end</langsyntaxhighlight>
"Integer aware" solution:
<langsyntaxhighlight lang=snobol> nums = "0123456789"
input span(nums) . a break(nums) span(nums) . b
output = a + b
end</langsyntaxhighlight>
 
=={{header|SPAD}}==
Line 5,087:
{{works with|Axiom}}
One of several possibilities:
<langsyntaxhighlight lang=SPAD>(1) -> integer READ()$Lisp + integer READ()$Lisp
333 444
 
(1) 777
Type: PositiveInteger</langsyntaxhighlight>
 
Domain:[http://fricas.github.io/api/SExpression.html?highlight=lisp SExpression]
 
=={{header|SPARK}}==
<langsyntaxhighlight lang=Ada>-- By Jacob Sparre Andersen
-- Validates with SPARK GPL 2010's Examiner/Simplifier
 
Line 5,139:
Stop => 0);
end if;
end A_Plus_B;</langsyntaxhighlight>
 
=={{header|SPL}}==
<langsyntaxhighlight lang=spl>n = #.split(#.input("Input two numbers, separated by space:")," ")
#.output(n[1],"+",n[2],"=",#.val(n[1])+#.val(n[2]))</langsyntaxhighlight>
{{in}}
<pre>
Line 5,155:
 
=={{header|SQL}}==
<syntaxhighlight lang =sql>select A+B</langsyntaxhighlight>
Example:
<syntaxhighlight lang =sql>select 2+3</langsyntaxhighlight>
This should produce a result set containing the value 5.
 
Line 5,165:
{{works with|Db2 LUW}}
With SQL only:
<langsyntaxhighlight lang=sql pl>
 
CREATE OR REPLACE FUNCTION splitadd (instring VARCHAR(255))
Line 5,180:
return first + second;
END
</syntaxhighlight>
</lang>
Output:
<pre>
Line 5,191:
=={{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>).
<langsyntaxhighlight lang=ssem>10100000000000100000000000000000 0. -5 to c acc = -A
01100000000001010000000000000000 1. Sub. 6 acc -= B
11100000000001100000000000000000 2. c to 7 X = acc
Line 5,198:
10100100000000000000000000000000 5. 37 A
00111000000000000000000000000000 6. 28 B
00000000000000000000000000000000 7. 0 X</langsyntaxhighlight>
 
=={{header|Standard ML}}==
<langsyntaxhighlight lang=sml>(*
* val split : string -> string list
* splits a string at it spaces
Line 5,222:
in
(sum o List.mapPartial Int.fromString o split) input
end</langsyntaxhighlight>
{{out}}
<pre>
Line 5,233:
{{works with|Swift|2}}
Requires sending EOF.
<langsyntaxhighlight lang=Swift>import Foundation
 
let input = NSFileHandle.fileHandleWithStandardInput()
Line 5,244:
let b = (nums[1] as String).toInt()!
 
print(" \(a + b)")</langsyntaxhighlight>
 
{{works with|Swift|3}}
Line 5,250:
Swift 4 and no requirement to send EOF (press enter/send newline like you normally would)
 
<langsyntaxhighlight lang=Swift>
import Foundation
 
Line 5,265:
 
print(" \(a + b)")
</syntaxhighlight>
</lang>
 
=={{header|Symsyn}}==
<langsyntaxhighlight lang=Symsyn>
 
[] $s
Line 5,276:
y []
 
</syntaxhighlight>
</lang>
 
=={{header|Tailspin}}==
<langsyntaxhighlight lang=tailspin>
composer nums
[ (<WS>?) <INT> (<WS>) <INT> (<WS>?) ]
Line 5,286:
$IN::lines -> nums -> $(1) + $(2) -> '$;
' -> !OUT::write
</syntaxhighlight>
</lang>
 
Alternatively
<langsyntaxhighlight lang=tailspin>
composer nums
(<WS>?) (def a: <INT>;) (<WS>) <INT> -> $a + $ (<WS>?)
Line 5,296:
$IN::lines -> nums -> '$;
' -> !OUT::write
</syntaxhighlight>
</lang>
 
=={{header|Tcl}}==
<langsyntaxhighlight lang=tcl>scan [gets stdin] "%d %d" x y
puts [expr {$x + $y}]</langsyntaxhighlight>
Alternatively:
<langsyntaxhighlight lang=tcl>puts [tcl::mathop::+ {*}[gets stdin]]</langsyntaxhighlight>
To/from a file:
<langsyntaxhighlight lang=tcl>set in [open "input.txt"]
set out [open "output.txt" w]
scan [gets $in] "%d %d" x y
puts $out [expr {$x + $y}]
close $in
close $out</langsyntaxhighlight>
 
=={{header|Terraform}}==
<langsyntaxhighlight lang=hcl>
#Aamrun, August 15th, 2022
 
Line 5,326:
value = var.a + var.b
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 5,345:
 
=={{header|TI-83 BASIC}}==
<langsyntaxhighlight lang=ti83b>:Prompt A,B
:Disp A+B</langsyntaxhighlight>
 
=={{header|TI-83 Hex Assembly}}==
Line 5,352:
Note: Comments (after the semicolons) are just for explanation -- TI-83 hex assembly does not allow comments in program source code.
 
<langsyntaxhighlight lang=ti83b>PROGRAM:APLUSB
:AsmPrgm
:
Line 5,368:
:F7 ; rst FPAdd
:EFBF4A ; StoAns
:C9 ; ret</langsyntaxhighlight>
 
Store the inputs in the 'A' and 'B' OS variables. Run it with Asm(prgmAPLUSB) and the output will be stored in the Ans OS variable.
 
=={{header|TI-89 BASIC}}==
<langsyntaxhighlight lang=ti89b>:aplusb(a,b)
:a+b</langsyntaxhighlight>
 
=={{header|TorqueScript}}==
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.
<langsyntaxhighlight lang=Torque>Function aPlusB(%input)
{
return getWord(%input, 0) + getWord(%input, 1);
}</langsyntaxhighlight>
 
=={{header|Transd}}==
<langsyntaxhighlight lang=scheme>#lang transd
 
MainModule : {
Line 5,391:
b: Int(),
_start: (lambda (textout (+ (read a) (read b))))
}</langsyntaxhighlight>
 
=={{header|TSE SAL}}==
<langsyntaxhighlight lang=TSESAL>
INTEGER PROC FNMathGetSumAPlusBI( INTEGER A, INTEGER B )
RETURN( A + B )
Line 5,406:
Message( FNMathGetSumAPlusBI( Val( s1 ), Val( s2 ) ) ) // gives e.g. 5
END
</syntaxhighlight>
</lang>
{{out}} <pre>
output
Line 5,413:
 
=={{header|TUSCRIPT}}==
<langsyntaxhighlight lang=tuscript>$$ MODE TUSCRIPT
SET input="1 2"
SET input=SPLIT(input,": :")
SET input=JOIN (input)
SET output=SUM(input)</langsyntaxhighlight>
 
=={{header|TXR}}==
Line 5,434:
=={{header|UNIX Shell}}==
{{works with|Bourne Shell}}
<langsyntaxhighlight lang=sh>#!/bin/sh
read a b || exit
echo `expr "$a" + "$b"`</langsyntaxhighlight>
 
{{works with|bash}}
Line 5,443:
{{works with|zsh}}
Script "a+b.sh":
<langsyntaxhighlight lang=bash>#!/bin/bash
read a b || exit
echo $(( a + b ))</langsyntaxhighlight>
{{Out}}
<langsyntaxhighlight lang=bash>echo 2 3 | ksh a+b.sh
5</langsyntaxhighlight>
 
One liner :
 
<langsyntaxhighlight lang=bash>
a=0;b=0;read a;read b;echo "Sum of $a and $b is "$((a+b))
</syntaxhighlight>
</lang>
Sample run :
<pre>
Line 5,463:
 
==={{header|C Shell}}===
<langsyntaxhighlight lang=csh>set line=$<
set input=($line)
@ sum = $input[1] + $input[2]
echo $sum</langsyntaxhighlight>
 
=={{header|Ursa}}==
Line 5,483:
 
# output the sum
out sum endl console</langsyntaxhighlight>
 
=={{header|Ultimate++}}==
 
<langsyntaxhighlight lang=Cpp>
#include <Core/Core.h>
#include <stdio.h>
Line 5,508:
 
 
</syntaxhighlight>
</lang>
 
 
=={{header|Ursala}}==
Using standard input and output streams:
<langsyntaxhighlight lang=Ursala>#import std
#import int
 
#executable&
 
main = %zP+ sum:-0+ %zp*FiNCS+ sep` @L</langsyntaxhighlight>
Overwriting a text file named as a command line parameter:
<langsyntaxhighlight lang=Ursala>#import std
#import int
 
#executable -[parameterized]-
 
main = ~command.files.&h; <.contents:= %zP+ sum:-0+ %zp*FiNCS+ sep` @L+ ~contents></langsyntaxhighlight>
Creating a new file named after the input file with suffix <code>.out</code>:
<langsyntaxhighlight lang=Ursala>#import std
#import int
 
Line 5,536:
~command.files.&h; ~&iNC+ file$[
contents: %zP+ sum:-0+ %zp*FiNCS+ sep` @L+ ~contents,
path: ~path; ^|C\~& ~=`.-~; ^|T/~& '.out'!]</langsyntaxhighlight>
 
=={{header|Vala}}==
Read from stdin while program running:
<langsyntaxhighlight lang=vala>Using GLib;
 
int main (string[] args) {
Line 5,550:
return 0;
}
</syntaxhighlight>
</lang>
 
=={{header|VBA}}==
A simple version:
<langsyntaxhighlight lang=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,561:
b = CInt(t(1))
MsgBox a + b
End Sub</langsyntaxhighlight>
An other version:
<langsyntaxhighlight lang=VBA>Sub Rosetta_AB()
Dim stEval As String
stEval = InputBox("Enter two numbers, separated only by a space", "Rosetta Code", "2 2")
Line 5,569:
"VBA converted this input to " & Replace(stEval, " ", "+") & vbCr & vbCr & _
"And evaluated the result as " & Evaluate(Replace(stEval, " ", "+")), vbInformation + vbOKOnly, "XLSM"
End Sub</langsyntaxhighlight>
 
=={{header|VBScript}}==
A simple version:
<langsyntaxhighlight lang=vb>s=InputBox("Enter two numbers separated by a blank")
t=Split(s)
a=CInt(t(0))
b=CInt(t(1))
c=a+b
MsgBox c </langsyntaxhighlight>
An other version:
<langsyntaxhighlight lang=vb>Option Explicit
Dim a, b
Select Case WScript.Arguments.Count
Line 5,616:
.Close
End With
end if</langsyntaxhighlight>
 
=={{header|Verilog}}==
<langsyntaxhighlight lang=Verilog>module TEST;
 
reg signed [11:0] y;
Line 5,637:
endfunction
endmodule</langsyntaxhighlight>
 
=={{header|VHDL}}==
<langsyntaxhighlight lang=VHDL>LIBRARY std;
USE std.TEXTIO.all;
 
Line 5,662:
wait; -- needed to stop the execution
end process;
end architecture beh;</langsyntaxhighlight>
 
=={{header|Visual Basic .NET}}==
<langsyntaxhighlight lang=vbnet>Module Module1
 
Sub Main()
Line 5,674:
End Sub
 
End Module</langsyntaxhighlight>
 
=={{header|Vlang}}==
<langsyntaxhighlight lang=go>import os
 
fn main() {
Line 5,691:
println('$a + $b = ${a+b}')
}</langsyntaxhighlight>
Read from stdin
{{out}}
Line 5,701:
 
=={{header|Wee Basic}}==
<langsyntaxhighlight lang=Wee Basic>Print 1 "Enter number A:"
input a
Print 1 "Enter number B:"
Line 5,707:
let c=a+b
print 1 c
end</langsyntaxhighlight>
 
=={{header|Whitespace}}==
<langsyntaxhighlight lang=whitespace>
Line 5,722:
 
 
</syntaxhighlight>
</lang>
 
=={{header|Wisp}}==
{{trans|Scheme}}
<langsyntaxhighlight lang=scheme>
display : + (read) (read)
 
Line 5,733:
315
;; displays 629
</syntaxhighlight>
</lang>
 
=={{header|Wren}}==
<langsyntaxhighlight lang=ecmascript>import "io" for Stdin, Stdout
 
while (true) {
Line 5,750:
return
}
}</langsyntaxhighlight>
 
{{out}}
Line 5,761:
=={{header|X86 Assembly}}==
{{works with|NASM|Linux}}
<langsyntaxhighlight lang=asm>section .text
global _start
Line 5,820:
a resd 1
b resd 1
sum resd 1</langsyntaxhighlight>
This will not work on numbers over 0(from 1 to 0). This is due to the fact, numbers higher than 0(10,11, etc) are in fact strings when taken from the keyboard. A much longer conversion code is required to loop through and treat each number in the string as separate numbers. For example, The number '10' would have to be treated as a 1 and a 0.
 
=={{header|XBS}}==
Since XBS is written in Javascript, we have to use the Javascript prompt function to get inputs.
<langsyntaxhighlight lang=xbs>const Amount:number = toint(window.prompt("Input an amount"));
set Stream = [];
<|(*1..Amount)=>Stream.push(window.prompt("Input a number"));
Line 5,832:
set Result = 0;
<|(*Inputs)Result+=_;
log(Result);</langsyntaxhighlight>
{{out}}
If we input an amount of "2", then input "1" and "2", the output will be "3".
Line 5,840:
 
=={{header|xEec}}==
<langsyntaxhighlight lang=xEec>i# i# ma h#10 r o# p o$ p</langsyntaxhighlight>
 
=={{header|XLISP}}==
<langsyntaxhighlight lang=xlisp>(DEFUN A-PLUS-B ()
(DISPLAY "Enter two numbers separated by a space.")
(NEWLINE)
Line 5,849:
(DEFINE A (READ))
(DEFINE B (READ))
(+ A B))</langsyntaxhighlight>
{{out}}
<pre>(A-PLUS-B)
Line 5,858:
 
=={{header|Xojo}}==
<langsyntaxhighlight lang=xojo>var inp as string
var strVals() as string
 
Line 5,884:
exit
loop
</syntaxhighlight>
</lang>
 
=={{header|XPL0}}==
<langsyntaxhighlight lang=XPL0>include c:\cxpl\codes;
int A, B;
[A:= IntIn(0);
Line 5,893:
IntOut(0, A+B);
CrLf(0);
]</langsyntaxhighlight>
 
=={{header|XQuery}}==
<langsyntaxhighlight lang=xquery>
(:
Using the EXPath File Module, which is built into most XQuery processors
Line 5,912:
let $result := xs:numeric($numbers[1]) + xs:numeric($numbers[2])
return file:write-text($out, xs:string($result))
</syntaxhighlight>
</lang>
 
=={{header|Yabasic}}==
<langsyntaxhighlight lang=Yabasic>repeat
input "Enter two numbers (betwen -1000 ... +1000): " a, b
until(valid(a) and valid(b))
Line 5,922:
sub valid(x)
return x >= -1000 and x <= 1000
end sub</langsyntaxhighlight>
 
=={{header|Yorick}}==
<langsyntaxhighlight lang=yorick>a = b = 0;
read, a, b;
write, a + b;</langsyntaxhighlight>
 
=={{header|ZED}}==
Source -> http://ideone.com/WLtEfe
Compiled -> http://ideone.com/fMt6ST
<langsyntaxhighlight lang=zed>(A+B)
comment:
#true
Line 5,945:
comment:
#true
(001) "read"</langsyntaxhighlight>
 
=={{header|zkl}}==
<langsyntaxhighlight lang=zkl>do(2){ask("A B: ").split(" ").filter().sum().println()}</langsyntaxhighlight>
<pre>
A B: 123 567
Line 5,958:
 
=={{header|Zoea}}==
<langsyntaxhighlight lang=Zoea>program: a_plus_b
input: '7 11'
output: 18
</syntaxhighlight>
</lang>
 
=={{header|Zoea Visual}}==
Line 5,967:
 
=={{header|zonnon}}==
<langsyntaxhighlight lang=zonnon>
module ABProblem;
var
Line 5,975:
writeln(a+b)
end ABProblem.
</syntaxhighlight>
</lang>
<pre>
1 2
Line 5,982:
 
=={{header|ZX Spectrum Basic}}==
<langsyntaxhighlight lang=zxbasic>10 PRINT "Input two numbers separated by"'"space(s) "
20 INPUT LINE a$
30 GO SUB 90
Line 5,991:
80 REM LTrim operation
90 IF a$(1)=" " THEN LET a$=a$(2 TO ): GO TO 90
100 RETURN</langsyntaxhighlight>
 
Another solution
 
<langsyntaxhighlight 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
Line 6,003:
70 LET i=i+1: GO TO 40
80 LET a=VAL a$( TO i): LET b=VAL a$(i TO )
90 PRINT a;" + ";b;" = ";a+b</langsyntaxhighlight>
 
<pre>
10,333

edits