A+B: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
m (Automated syntax highlighting fixup (second round - minor fixes))
Line 32: Line 32:


=={{header|0815}}==
=={{header|0815}}==
<syntaxhighlight lang=0815>|x|+%</syntaxhighlight>
<syntaxhighlight lang="0815">|x|+%</syntaxhighlight>


=={{header|11l}}==
=={{header|11l}}==
{{trans|Python}}
{{trans|Python}}
<syntaxhighlight lang=11l>print(sum(input().split(‘ ’, group_delimiters' 1B).map(i -> Int(i))))</syntaxhighlight>
<syntaxhighlight lang="11l">print(sum(input().split(‘ ’, group_delimiters' 1B).map(i -> Int(i))))</syntaxhighlight>


=={{header|360 Assembly}}==
=={{header|360 Assembly}}==
<syntaxhighlight lang=360asm>* A+B 29/08/2015
<syntaxhighlight lang="360asm">* A+B 29/08/2015
APLUSB CSECT
APLUSB CSECT
USING APLUSB,R12
USING APLUSB,R12
Line 75: Line 75:


=={{header|8th}}==
=={{header|8th}}==
<syntaxhighlight lang=forth>gets dup . space eval n:+ . cr</syntaxhighlight>
<syntaxhighlight lang="forth">gets dup . space eval n:+ . cr</syntaxhighlight>


=={{header|8080 Assembly}}==
=={{header|8080 Assembly}}==
Line 86: Line 86:
which can take four forms:
which can take four forms:


<syntaxhighlight lang=8080asm> dad b ; HL += BC (i.e., add BC reg pair to HL reg pair)
<syntaxhighlight lang="8080asm"> dad b ; HL += BC (i.e., add BC reg pair to HL reg pair)
dad d ; HL += DE
dad d ; HL += DE
dad h ; HL += HL (also known as "mul HL by two")
dad h ; HL += HL (also known as "mul HL by two")
Line 93: Line 93:
Merely doing A+B, with 16-bit numbers so that <math>(-1000 \le A,B \le +1000)</math> will fit,
Merely doing A+B, with 16-bit numbers so that <math>(-1000 \le A,B \le +1000)</math> will fit,
would look like this:
would look like this:
<syntaxhighlight lang=8080asm> lxi h,123
<syntaxhighlight lang="8080asm"> lxi h,123
lxi d,456
lxi d,456
dad d
dad d
Line 104: Line 104:
fits exactly in one CP/M block.
fits exactly in one CP/M block.


<syntaxhighlight lang=8080asm>fcb1n: equ 5Ch+1 ; "Filename" in first FCB
<syntaxhighlight lang="8080asm">fcb1n: equ 5Ch+1 ; "Filename" in first FCB
fcb2n: equ 6Ch+1 ; "Filename" in second FCB
fcb2n: equ 6Ch+1 ; "Filename" in second FCB
puts: equ 9 ; CP/M call to write string to console
puts: equ 9 ; CP/M call to write string to console
Line 209: Line 209:
=={{header|AArch64 Assembly}}==
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang=AArch64 Assembly>
<syntaxhighlight lang="aarch64 assembly">
/* ARM assembly AARCH64 Raspberry PI 3B */
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program addAetB.s */
/* program addAetB.s */
Line 409: Line 409:


=={{header|ABAP}}==
=={{header|ABAP}}==
<syntaxhighlight lang=ABAP>report z_sum_a_b.
<syntaxhighlight lang="abap">report z_sum_a_b.
data: lv_output type i.
data: lv_output type i.
selection-screen begin of block input.
selection-screen begin of block input.
Line 426: Line 426:


=={{header|Action!}}==
=={{header|Action!}}==
<syntaxhighlight lang=Action!>BYTE FUNC Find(CHAR ARRAY s CHAR c BYTE POINTER err)
<syntaxhighlight lang="action!">BYTE FUNC Find(CHAR ARRAY s CHAR c BYTE POINTER err)
BYTE i
BYTE i
FOR i=1 TO s(0)
FOR i=1 TO s(0)
Line 503: Line 503:


=={{header|Ada}}==
=={{header|Ada}}==
<syntaxhighlight lang=Ada>-- Standard I/O Streams
<syntaxhighlight lang="ada">-- Standard I/O Streams


with Ada.Integer_Text_Io;
with Ada.Integer_Text_Io;
Line 514: Line 514:
end APlusB;</syntaxhighlight>
end APlusB;</syntaxhighlight>
Using appropriate user defined types:
Using appropriate user defined types:
<syntaxhighlight lang=Ada>with Ada.Text_IO;
<syntaxhighlight lang="ada">with Ada.Text_IO;


procedure A_Plus_B is
procedure A_Plus_B is
Line 529: Line 529:
=={{header|Agena}}==
=={{header|Agena}}==
Tested with Agena 2.9.5 Win32
Tested with Agena 2.9.5 Win32
<syntaxhighlight lang=agena>scope
<syntaxhighlight lang="agena">scope
local f := trim( io.read() ) split " "; # read a line and split into fields
local f := trim( io.read() ) split " "; # read a line and split into fields
local a := tonumber( f[ 1 ] );
local a := tonumber( f[ 1 ] );
Line 537: Line 537:


=={{header|Aime}}==
=={{header|Aime}}==
<syntaxhighlight lang=aime>file f;
<syntaxhighlight lang="aime">file f;
list l;
list l;


Line 547: Line 547:
=={{header|ALGOL 60}}==
=={{header|ALGOL 60}}==
{{works with|A60}}
{{works with|A60}}
<syntaxhighlight lang=algol60>begin
<syntaxhighlight lang="algol60">begin
comment A+B;
comment A+B;
integer a,b;
integer a,b;
Line 569: Line 569:
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - missing transput function "read int"}}
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - missing transput function "read int"}}
===Console===
===Console===
<syntaxhighlight lang=algol68>print((read int + read int))</syntaxhighlight>
<syntaxhighlight lang="algol68">print((read int + read int))</syntaxhighlight>
Input:
Input:
<pre>
<pre>
Line 580: Line 580:


===File===
===File===
<syntaxhighlight lang=algol68>open(stand in, "input.txt", stand in channel);
<syntaxhighlight lang="algol68">open(stand in, "input.txt", stand in channel);
open(stand out, "output.txt", stand out channel);
open(stand out, "output.txt", stand out channel);
print((read int + read int))</syntaxhighlight>
print((read int + read int))</syntaxhighlight>
Line 593: Line 593:


=={{header|ALGOL W}}==
=={{header|ALGOL W}}==
<syntaxhighlight lang=algolw>begin
<syntaxhighlight lang="algolw">begin
integer a, b;
integer a, b;
read( a, b );
read( a, b );
Line 600: Line 600:


=={{header|Amazing Hopper}}==
=={{header|Amazing Hopper}}==
<syntaxhighlight lang=Amazing Hopper>
<syntaxhighlight lang="amazing hopper">
#include <hbasic.h>
#include <hbasic.h>


Line 625: Line 625:
Version dos: hopper-BASIC acepta "programación fluída"
Version dos: hopper-BASIC acepta "programación fluída"


<syntaxhighlight lang=Amazing Hopper>
<syntaxhighlight lang="amazing hopper">
#include <hbasic.h>
#include <hbasic.h>


Line 660: Line 660:


=={{header|Apex}}==
=={{header|Apex}}==
<syntaxhighlight lang=Apex>
<syntaxhighlight lang="apex">


static Integer sumOfTwoNums(Integer A, Integer B) {
static Integer sumOfTwoNums(Integer A, Integer B) {
Line 680: Line 680:


=={{header|APL}}==
=={{header|APL}}==
<syntaxhighlight lang=APL> ⎕+⎕ </syntaxhighlight>
<syntaxhighlight lang="apl"> ⎕+⎕ </syntaxhighlight>


=={{header|AppleScript}}==
=={{header|AppleScript}}==
Open the '''AppleScript Editor''' and save this as '''A+B.scpt''' on your Desktop
Open the '''AppleScript Editor''' and save this as '''A+B.scpt''' on your Desktop
<syntaxhighlight lang=AppleScript>on run argv
<syntaxhighlight lang="applescript">on run argv
try
try
return ((first item of argv) as integer) + (second item of argv) as integer
return ((first item of argv) as integer) + (second item of argv) as integer
Line 700: Line 700:


=={{header|Arc}}==
=={{header|Arc}}==
<syntaxhighlight lang=Arc>
<syntaxhighlight lang="arc">
(prn (+ (read)
(prn (+ (read)
(read)))
(read)))
Line 708: Line 708:
{{trans|C}}
{{trans|C}}
{{works with|Argile|1.0.0}}
{{works with|Argile|1.0.0}}
<syntaxhighlight lang=Argile>(: Standard input-output streams :)
<syntaxhighlight lang="argile">(: Standard input-output streams :)
use std, array
use std, array
Cfunc scanf "%d%d" (&val int a) (&val int b)
Cfunc scanf "%d%d" (&val int a) (&val int b)
printf "%d\n" (a + b)</syntaxhighlight>
printf "%d\n" (a + b)</syntaxhighlight>
<syntaxhighlight lang=Argile>(: Input file : input.txt :)
<syntaxhighlight lang="argile">(: Input file : input.txt :)
(: Output file: output.txt :)
(: Output file: output.txt :)
use std, array
use std, array
Line 727: Line 727:
Exploiting C standard library functions (scanf and printf).
Exploiting C standard library functions (scanf and printf).
Requires arm-linux-gnueabi-gcc and qemu-arm. Compile with:
Requires arm-linux-gnueabi-gcc and qemu-arm. Compile with:
<syntaxhighlight lang=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-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>.text
<syntaxhighlight lang="arm_assembly">.text
.global main
.global main
.extern printf
.extern printf
Line 775: Line 775:
Save in ab.S
Save in ab.S
Build with:
Build with:
<syntaxhighlight lang=ARM_Assembly>as -o ab.o ab.S
<syntaxhighlight lang="arm_assembly">as -o ab.o ab.S
ld -o a.out ab.o</syntaxhighlight>
ld -o a.out ab.o</syntaxhighlight>


<syntaxhighlight lang=ARM_Assembly>.data
<syntaxhighlight lang="arm_assembly">.data
.align 2
.align 2
.code 32
.code 32
Line 1,295: Line 1,295:
=={{header|Arturo}}==
=={{header|Arturo}}==


<syntaxhighlight lang=rebol>while ø [
<syntaxhighlight lang="rebol">while ø [
x: map split.words input "give me 2 numbers:" 'x -> to :integer x
x: map split.words input "give me 2 numbers:" 'x -> to :integer x
print add x\0 x\1
print add x\0 x\1
Line 1,316: Line 1,316:


=={{header|ATS}}==
=={{header|ATS}}==
<syntaxhighlight lang=ATS>
<syntaxhighlight lang="ats">
(* ****** ****** *)
(* ****** ****** *)
//
//
Line 1,347: Line 1,347:
=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
This handles more than two inputs
This handles more than two inputs
<syntaxhighlight lang=AutoHotkey>Gui, Add, Edit, vEdit ;Enter your A+B, i.e. 5+3 or 5+3+1+4+6+2
<syntaxhighlight 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, Button, gAdd, Add
Gui, Add, Edit, ReadOnly x+10 w80
Gui, Add, Edit, ReadOnly x+10 w80
Line 1,362: Line 1,362:


=={{header|AutoIt}}==
=={{header|AutoIt}}==
<syntaxhighlight lang=AutoIt>;AutoIt Version: 3.2.10.0
<syntaxhighlight lang="autoit">;AutoIt Version: 3.2.10.0
$num = "45 54"
$num = "45 54"
consolewrite ("Sum of " & $num & " is: " & sum($num))
consolewrite ("Sum of " & $num & " is: " & sum($num))
Line 1,372: Line 1,372:
===Example2===
===Example2===
This version can handle any amount of numbers in the input:
This version can handle any amount of numbers in the input:
<syntaxhighlight lang=AutoIt>ConsoleWrite("# A+B:" & @CRLF)
<syntaxhighlight lang="autoit">ConsoleWrite("# A+B:" & @CRLF)


Func Sum($inp)
Func Sum($inp)
Line 1,402: Line 1,402:


=={{header|AWK}}==
=={{header|AWK}}==
<syntaxhighlight lang=awk>{print $1 + $2}</syntaxhighlight>
<syntaxhighlight lang="awk">{print $1 + $2}</syntaxhighlight>


=={{header|BASIC}}==
=={{header|BASIC}}==
<syntaxhighlight lang=qbasic>DEFINT A-Z
<syntaxhighlight lang="qbasic">DEFINT A-Z


tryagain:
tryagain:
Line 1,423: Line 1,423:


==={{header|Applesoft BASIC}}===
==={{header|Applesoft BASIC}}===
<syntaxhighlight lang=ApplesoftBasic>10 BH = PEEK(37)
<syntaxhighlight 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
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
40 IF LEN(I$) THEN IF MID$(I$, LEN(I$), 1) = " " THEN I$ = MID$(I$, 1, LEN(I$) - 1) : GOTO 40RTRIM
Line 1,436: Line 1,436:


==={{header|BaCon}}===
==={{header|BaCon}}===
<syntaxhighlight lang=qbasic>' A+B
<syntaxhighlight lang="qbasic">' A+B
INPUT d$
INPUT d$
PRINT VAL(TOKEN$(d$, 1)) + VAL(TOKEN$(d$, 2))</syntaxhighlight>
PRINT VAL(TOKEN$(d$, 1)) + VAL(TOKEN$(d$, 2))</syntaxhighlight>


==={{header|BASIC256}}===
==={{header|BASIC256}}===
<syntaxhighlight lang=basic256>dim a(2)
<syntaxhighlight lang="basic256">dim a(2)
input "Enter two numbers separated by a space?", t$
input "Enter two numbers separated by a space?", t$
a = explode(t$," ")
a = explode(t$," ")
Line 1,447: Line 1,447:


==={{header|BBC BASIC}}===
==={{header|BBC BASIC}}===
<syntaxhighlight lang=bbc> REPEAT
<syntaxhighlight lang="bbc"> REPEAT
hereY% = VPOS
hereY% = VPOS
INPUT LINE "" q$
INPUT LINE "" q$
Line 1,462: Line 1,462:
UNTIL FALSE</syntaxhighlight>
UNTIL FALSE</syntaxhighlight>
That seems overly complicated. What's wrong with:
That seems overly complicated. What's wrong with:
<syntaxhighlight lang=bbc> REPEAT
<syntaxhighlight lang="bbc"> REPEAT
INPUT LINE "" q$
INPUT LINE "" q$
space% = INSTR(q$," ")
space% = INSTR(q$," ")
Line 1,469: Line 1,469:


==={{header|Commodore BASIC}}===
==={{header|Commodore BASIC}}===
<syntaxhighlight lang=qbasic>10 PRINT "ENTER TWO NUMBERS, SEPARATED BY A SPACE: ";
<syntaxhighlight lang="qbasic">10 PRINT "ENTER TWO NUMBERS, SEPARATED BY A SPACE: ";
20 INPUT X$
20 INPUT X$
30 I = 1 : N = LEN(X$)
30 I = 1 : N = LEN(X$)
Line 1,478: Line 1,478:


==={{header|FreeBASIC}}===
==={{header|FreeBASIC}}===
<syntaxhighlight lang=freebasic>' fb 1.05.0 Win64
<syntaxhighlight lang="freebasic">' fb 1.05.0 Win64


Dim As Integer a, b
Dim As Integer a, b
Line 1,497: Line 1,497:


==={{header|FUZE BASIC}}===
==={{header|FUZE BASIC}}===
<syntaxhighlight lang=qbasic>INPUT n$
<syntaxhighlight lang="qbasic">INPUT n$
PRINT VAL(LEFT$(n$,(LEN(STR$(VAL(n$))))))+VAL(RIGHT$(n$,(LEN(n$)-LEN(STR$(VAL(n$)))-1)))
PRINT VAL(LEFT$(n$,(LEN(STR$(VAL(n$))))))+VAL(RIGHT$(n$,(LEN(n$)-LEN(STR$(VAL(n$)))-1)))
END</syntaxhighlight>
END</syntaxhighlight>


==={{header|IS-BASIC}}===
==={{header|IS-BASIC}}===
<syntaxhighlight lang=IS-BASIC>100 DO
<syntaxhighlight lang="is-basic">100 DO
110 INPUT PROMPT "Ener two integers separated by a comma: ":A,B
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
120 IF ABS(A)>1000 OR ABS(B)>1000 OR IP(A)<>A OR IP(B)<>B THEN
Line 1,513: Line 1,513:


==={{header|Liberty BASIC}}===
==={{header|Liberty BASIC}}===
<syntaxhighlight lang=lb>input, n$
<syntaxhighlight lang="lb">input, n$
print eval(word$(n$,1);" + ";word$(n$,2))</syntaxhighlight>
print eval(word$(n$,1);" + ";word$(n$,2))</syntaxhighlight>


==={{header|OxygenBasic}}===
==={{header|OxygenBasic}}===
<lang>
<syntaxhighlight lang="text">
uses console
uses console
int i
int i
Line 1,533: Line 1,533:


==={{header|Sinclair ZX81 BASIC}}===
==={{header|Sinclair ZX81 BASIC}}===
<syntaxhighlight lang=basic>10 INPUT A$
<syntaxhighlight lang="basic">10 INPUT A$
20 LET I=1
20 LET I=1
30 IF A$(I)=" " THEN GOTO 60
30 IF A$(I)=" " THEN GOTO 60
Line 1,541: Line 1,541:


==={{Header|Tiny BASIC}}===
==={{Header|Tiny BASIC}}===
<syntaxhighlight lang=Tiny BASIC>REM Rosetta Code problem: https://rosettacode.org/wiki/A+B
<syntaxhighlight lang="tiny basic">REM Rosetta Code problem: https://rosettacode.org/wiki/A+B
REM by Jjuanhdez, 06/2022
REM by Jjuanhdez, 06/2022


Line 1,561: Line 1,561:


==={{header|True BASIC}}===
==={{header|True BASIC}}===
<syntaxhighlight lang=qbasic>DO
<syntaxhighlight lang="qbasic">DO
INPUT PROMPT "Enter two integers separated by a comma: ": A, B
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
IF ABS(A)>1000 OR ABS(B)>1000 OR IP(A)<>A OR IP(B)<>B THEN
Line 1,573: Line 1,573:
END</syntaxhighlight>
END</syntaxhighlight>
==={{header|uBasic/4tH}}===
==={{header|uBasic/4tH}}===
<lang>s = FUNC(_GetInt(1000)) + FUNC(_GetInt(1000))
<syntaxhighlight lang="text">s = FUNC(_GetInt(1000)) + FUNC(_GetInt(1000))
Print "The sum is: ";s
Print "The sum is: ";s
End
End
Line 1,590: Line 1,590:
=={{header|Batch File}}==
=={{header|Batch File}}==
Prompts version
Prompts version
<syntaxhighlight lang=dos>::aplusb.cmd
<syntaxhighlight lang="dos">::aplusb.cmd
@echo off
@echo off
setlocal
setlocal
Line 1,599: Line 1,599:
endlocal</syntaxhighlight>
endlocal</syntaxhighlight>
All on the commandline version
All on the commandline version
<syntaxhighlight lang=dos>::aplusb.cmd
<syntaxhighlight lang="dos">::aplusb.cmd
@echo off
@echo off
setlocal
setlocal
Line 1,608: Line 1,608:
endlocal</syntaxhighlight>
endlocal</syntaxhighlight>
Formula on the command line version
Formula on the command line version
<syntaxhighlight lang=dos>::aplusb.cmd
<syntaxhighlight lang="dos">::aplusb.cmd
@echo off
@echo off
setlocal
setlocal
Line 1,622: Line 1,622:
</pre>
</pre>
Parse the input stream version (thanks to Tom Lavedas on alt.msdos.batch.nt)
Parse the input stream version (thanks to Tom Lavedas on alt.msdos.batch.nt)
<syntaxhighlight lang=dos>::aplusb.cmd
<syntaxhighlight lang="dos">::aplusb.cmd
@echo off
@echo off
setlocal
setlocal
Line 1,645: Line 1,645:
=={{header|bc}}==
=={{header|bc}}==
{{Works with|GNU bc}}
{{Works with|GNU bc}}
<syntaxhighlight lang=bc>read() + read()</syntaxhighlight>
<syntaxhighlight lang="bc">read() + read()</syntaxhighlight>


=={{header|Befunge}}==
=={{header|Befunge}}==
<syntaxhighlight lang=befunge>&&+.@</syntaxhighlight>
<syntaxhighlight lang="befunge">&&+.@</syntaxhighlight>


=={{header|Bird}}==
=={{header|Bird}}==
<syntaxhighlight lang=Bird>use Console Math
<syntaxhighlight lang="bird">use Console Math


define Main
define Main
Line 1,670: Line 1,670:
=={{header|bootBASIC}}==
=={{header|bootBASIC}}==
Both numbers are entered separately.
Both numbers are entered separately.
<syntaxhighlight lang=bootBASIC>10 print "Number 1";
<syntaxhighlight lang="bootbasic">10 print "Number 1";
20 input a
20 input a
30 print "Number 2";
30 print "Number 2";
Line 1,680: Line 1,680:
{{works with|https://github.com/dzaima/CBQN CBQN}}
{{works with|https://github.com/dzaima/CBQN CBQN}}


<syntaxhighlight lang=bqn>#!/usr/bin/env bqn
<syntaxhighlight lang="bqn">#!/usr/bin/env bqn


# Cut 𝕩 at occurrences of 𝕨, removing separators and empty segments
# Cut 𝕩 at occurrences of 𝕨, removing separators and empty segments
Line 1,697: Line 1,697:
=={{header|Bracmat}}==
=={{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.
<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
<syntaxhighlight lang="bracmat">( out
$ ( put$"Enter two integer numbers between -1000 and 1000:"
$ ( put$"Enter two integer numbers between -1000 and 1000:"
& (filter=~/#%:~<-1000:~>1000)
& (filter=~/#%:~<-1000:~>1000)
Line 1,707: Line 1,707:


=={{header|Brainf***}}==
=={{header|Brainf***}}==
<syntaxhighlight lang=brainf***>INPUT AND SUMMATION
<syntaxhighlight lang="brainf***">INPUT AND SUMMATION
TODO if first symbol is a minus sign print Qgo awayQ
TODO if first symbol is a minus sign print Qgo awayQ
+> initialize sum to one
+> initialize sum to one
Line 1,733: Line 1,733:


=={{header|Brat}}==
=={{header|Brat}}==
<syntaxhighlight lang=brat>numbers = g.split[0,1].map(:to_i)
<syntaxhighlight lang="brat">numbers = g.split[0,1].map(:to_i)
p numbers[0] + numbers[1] #Prints the sum of the input</syntaxhighlight>
p numbers[0] + numbers[1] #Prints the sum of the input</syntaxhighlight>


=={{header|Burlesque}}==
=={{header|Burlesque}}==
<syntaxhighlight lang=burlesque>ps++</syntaxhighlight>
<syntaxhighlight lang="burlesque">ps++</syntaxhighlight>


=={{header|C}}==
=={{header|C}}==
<syntaxhighlight lang=c>// Standard input-output streams
<syntaxhighlight lang="c">// Standard input-output streams
#include <stdio.h>
#include <stdio.h>
int main()
int main()
Line 1,749: Line 1,749:
return 0;
return 0;
}</syntaxhighlight>
}</syntaxhighlight>
<syntaxhighlight lang=c>// Input file: input.txt
<syntaxhighlight lang="c">// Input file: input.txt
// Output file: output.txt
// Output file: output.txt
#include <stdio.h>
#include <stdio.h>
Line 1,761: Line 1,761:
return 0;
return 0;
}</syntaxhighlight>
}</syntaxhighlight>
<syntaxhighlight lang=c>
<syntaxhighlight lang="c">
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
Line 1,772: Line 1,772:


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
<syntaxhighlight lang=csharp>using System;
<syntaxhighlight lang="csharp">using System;
using System.Linq;
using System.Linq;


Line 1,783: Line 1,783:
}</syntaxhighlight>
}</syntaxhighlight>
Another way (not recommended since it does not work with more than two numbers):
Another way (not recommended since it does not work with more than two numbers):
<syntaxhighlight lang=csharp>using System;
<syntaxhighlight lang="csharp">using System;


class Program
class Program
Line 1,799: Line 1,799:


=={{header|C++}}==
=={{header|C++}}==
<syntaxhighlight lang=cpp>// Standard input-output streams
<syntaxhighlight lang="cpp">// Standard input-output streams
#include <iostream>
#include <iostream>
using namespace std;
using namespace std;
Line 1,808: Line 1,808:
cout << a + b << endl;
cout << a + b << endl;
}</syntaxhighlight>
}</syntaxhighlight>
<syntaxhighlight lang=cpp>// Input file: input.txt
<syntaxhighlight lang="cpp">// Input file: input.txt
// Output file: output.txt
// Output file: output.txt
#include <fstream>
#include <fstream>
Line 1,823: Line 1,823:


=={{header|Ceylon}}==
=={{header|Ceylon}}==
<syntaxhighlight lang=ceylon>shared void run() {
<syntaxhighlight lang="ceylon">shared void run() {


print("please enter two numbers for me to add");
print("please enter two numbers for me to add");
Line 1,850: Line 1,850:


=={{header|Clojure}}==
=={{header|Clojure}}==
<syntaxhighlight lang=clojure>(println (+ (Integer/parseInt (read-line)) (Integer/parseInt (read-line))))
<syntaxhighlight lang="clojure">(println (+ (Integer/parseInt (read-line)) (Integer/parseInt (read-line))))
3
3
4
4
=>7</syntaxhighlight>
=>7</syntaxhighlight>
<syntaxhighlight lang=clojure>(eval (read-string (str "(+ " (read-line) " )") ))
<syntaxhighlight lang="clojure">(eval (read-string (str "(+ " (read-line) " )") ))
3 3
3 3
6</syntaxhighlight>
6</syntaxhighlight>


Translation of Common Lisp version:
Translation of Common Lisp version:
<syntaxhighlight lang=clojure>(println (+ (read) (read)))
<syntaxhighlight lang="clojure">(println (+ (read) (read)))
3 4
3 4
7</syntaxhighlight>
7</syntaxhighlight>
Line 1,865: Line 1,865:


Safely and without reader tricks:
Safely and without reader tricks:
<syntaxhighlight lang=clojure>(let [ints (map #(Integer/parseInt %) (clojure.string/split (read-line) #"\s") )]
<syntaxhighlight lang="clojure">(let [ints (map #(Integer/parseInt %) (clojure.string/split (read-line) #"\s") )]
(println (reduce + ints)))
(println (reduce + ints)))
3 4
3 4
Line 1,871: Line 1,871:


or same as above, but without "let":
or same as above, but without "let":
<syntaxhighlight lang=clojure>(println (reduce + (map #(Integer/parseInt %) (clojure.string/split (read-line) #"\s") )))
<syntaxhighlight lang="clojure">(println (reduce + (map #(Integer/parseInt %) (clojure.string/split (read-line) #"\s") )))


3 4
3 4
Line 1,877: Line 1,877:


=={{header|COBOL}}==
=={{header|COBOL}}==
<syntaxhighlight lang=cobol> IDENTIFICATION DIVISION.
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. A-Plus-B.
PROGRAM-ID. A-Plus-B.


Line 1,900: Line 1,900:
A second version.
A second version.


<syntaxhighlight lang=COBOL>
<syntaxhighlight lang="cobol">


IDENTIFICATION DIVISION.
IDENTIFICATION DIVISION.
Line 1,945: Line 1,945:
=={{header|CoffeeScript}}==
=={{header|CoffeeScript}}==
{{trans|JavaScript}}
{{trans|JavaScript}}
<syntaxhighlight lang=html4strict><html>
<syntaxhighlight lang="html4strict"><html>
<script type="text/javascript" src="http://jashkenas.github.com/coffee-script/extras/coffee-script.js"></script>
<script type="text/javascript" src="http://jashkenas.github.com/coffee-script/extras/coffee-script.js"></script>
<script type="text/coffeescript">
<script type="text/coffeescript">
Line 1,961: Line 1,961:


{{works with|Node.js}}
{{works with|Node.js}}
<syntaxhighlight lang=coffeescript>
<syntaxhighlight lang="coffeescript">
{ stdin } = process
{ stdin } = process
sum = ( a, b ) -> a + b
sum = ( a, b ) -> a + b
Line 1,995: Line 1,995:


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==
<syntaxhighlight lang=lisp>(write (+ (read) (read)))</syntaxhighlight>
<syntaxhighlight lang="lisp">(write (+ (read) (read)))</syntaxhighlight>


=={{header|Component Pascal}}==
=={{header|Component Pascal}}==
BlackBox Component Builder
BlackBox Component Builder
<syntaxhighlight lang=oberon2>
<syntaxhighlight lang="oberon2">
MODULE AB;
MODULE AB;
IMPORT StdLog, DevCommanders,TextMappers;
IMPORT StdLog, DevCommanders,TextMappers;
Line 2,037: Line 2,037:


=={{header|Computer/zero Assembly}}==
=={{header|Computer/zero Assembly}}==
<syntaxhighlight lang=czasm> STP ; wait for input
<syntaxhighlight lang="czasm"> STP ; wait for input
a: 0
a: 0
b: 0
b: 0
Line 2,045: Line 2,045:


=={{header|Crystal}}==
=={{header|Crystal}}==
<syntaxhighlight lang=ruby>puts gets.not_nil!.split.map(&.to_i).sum</syntaxhighlight>
<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.
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: Line 2,052:
To handle the <code>nil</code> case we could do:
To handle the <code>nil</code> case we could do:


<syntaxhighlight lang=ruby>if line = gets
<syntaxhighlight lang="ruby">if line = gets
puts line.split.map(&.to_i).sum
puts line.split.map(&.to_i).sum
else
else
Line 2,060: Line 2,060:
=={{header|D}}==
=={{header|D}}==
===From Console===
===From Console===
<syntaxhighlight lang=d>import std.stdio, std.conv, std.string;
<syntaxhighlight lang="d">import std.stdio, std.conv, std.string;


void main() {
void main() {
Line 2,074: Line 2,074:
<pre>30</pre>
<pre>30</pre>
===From File===
===From File===
<syntaxhighlight lang=d>void main() {
<syntaxhighlight lang="d">void main() {
import std.stdio, std.file;
import std.stdio, std.file;


Line 2,082: Line 2,082:


=={{header|Dart}}==
=={{header|Dart}}==
<syntaxhighlight lang=Dart>import 'dart:io';
<syntaxhighlight lang="dart">import 'dart:io';


// a little helper function that checks if the string only contains
// a little helper function that checks if the string only contains
Line 2,118: Line 2,118:


=={{header|dc}}==
=={{header|dc}}==
<syntaxhighlight lang=dc>? + psz</syntaxhighlight>
<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.)
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}}==
=={{header|DCL}}==
<syntaxhighlight lang=DCL>$ read sys$command line
<syntaxhighlight lang="dcl">$ read sys$command line
$ a = f$element( 0, " ", line )
$ a = f$element( 0, " ", line )
$ b = f$element( 1, " ", line )
$ b = f$element( 1, " ", line )
Line 2,130: Line 2,130:
=={{header|Delphi}}==
=={{header|Delphi}}==
Console version.
Console version.
<syntaxhighlight lang=delphi>program SUM;
<syntaxhighlight lang="delphi">program SUM;


{$APPTYPE CONSOLE}
{$APPTYPE CONSOLE}
Line 2,147: Line 2,147:


=={{header|Diego}}==
=={{header|Diego}}==
<syntaxhighlight lang=diego>set_namespace(rosettacode)_me();
<syntaxhighlight lang="diego">set_namespace(rosettacode)_me();
begin_instuct(A + B);
begin_instuct(A + B);
Line 2,164: Line 2,164:


=={{header|DMS}}==
=={{header|DMS}}==
<syntaxhighlight lang=DMS>number a = GetNumber( "Please input 'a'", a, a ) // prompts for 'a'
<syntaxhighlight lang="dms">number a = GetNumber( "Please input 'a'", a, a ) // prompts for 'a'
number b = GetNumber( "Please input 'b'", b, b ) // prompts for 'b'
number b = GetNumber( "Please input 'b'", b, b ) // prompts for 'b'
Result( a + b + "\n" )</syntaxhighlight>
Result( a + b + "\n" )</syntaxhighlight>


=={{header|Dragon}}==
=={{header|Dragon}}==
<syntaxhighlight lang=dragon>
<syntaxhighlight lang="dragon">
select "graphic"
select "graphic"
select "types"
select "types"
Line 2,181: Line 2,181:
=={{header|DWScript}}==
=={{header|DWScript}}==
Ghetto GUI version
Ghetto GUI version
<syntaxhighlight lang=delphi>var a := StrToInt(InputBox('A+B', 'Enter 1st number', '0'));
<syntaxhighlight lang="delphi">var a := StrToInt(InputBox('A+B', 'Enter 1st number', '0'));
var b := StrToInt(InputBox('A+B', 'Enter 2nd number', '0'));
var b := StrToInt(InputBox('A+B', 'Enter 2nd number', '0'));
ShowMessage('Sum is '+IntToStr(a+b));</syntaxhighlight>
ShowMessage('Sum is '+IntToStr(a+b));</syntaxhighlight>
Line 2,188: Line 2,188:
{{trans|Python}}
{{trans|Python}}
===Console===
===Console===
<syntaxhighlight lang=dejavu>0
<syntaxhighlight lang="dejavu">0
for k in split !prompt "" " ":
for k in split !prompt "" " ":
+ to-num k
+ to-num k
Line 2,194: Line 2,194:


=={{header|EasyLang}}==
=={{header|EasyLang}}==
<lang>a$ = input
<syntaxhighlight lang="text">a$ = input
while i < len a$ and substr a$ i 1 <> " "
while i < len a$ and substr a$ i 1 <> " "
i += 1
i += 1
Line 2,204: Line 2,204:


=={{header|EchoLisp}}==
=={{header|EchoLisp}}==
<syntaxhighlight lang=scheme>
<syntaxhighlight lang="scheme">
(+ (read-number 1 "value for A") (read-number 2 "value for B"))
(+ (read-number 1 "value for A") (read-number 2 "value for B"))
</syntaxhighlight>
</syntaxhighlight>
Line 2,210: Line 2,210:
=={{header|EDSAC order code}}==
=={{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.
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
<syntaxhighlight lang="edsac">[ A plus B
========
========
Line 2,260: 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.
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>
<syntaxhighlight lang="edsac">
[A + B for Rosetta Code.
[A + B for Rosetta Code.
Read two integers and find their sum.
Read two integers and find their sum.
Line 2,379: Line 2,379:
=={{header|EGL}}==
=={{header|EGL}}==


<syntaxhighlight lang=EGL>
<syntaxhighlight lang="egl">
package programs;
package programs;


Line 2,402: Line 2,402:
=={{header|Eiffel}}==
=={{header|Eiffel}}==
argument(0) contains the path of the executable - thus we start at argument(1)
argument(0) contains the path of the executable - thus we start at argument(1)
<syntaxhighlight lang=eiffel>
<syntaxhighlight lang="eiffel">
class
class
APPLICATION
APPLICATION
Line 2,419: Line 2,419:


Alternatively ...
Alternatively ...
<syntaxhighlight lang=eiffel>
<syntaxhighlight lang="eiffel">
make
make
-- Run application.
-- Run application.
Line 2,443: Line 2,443:


=={{header|Ela}}==
=={{header|Ela}}==
<syntaxhighlight lang=ela>open monad io string list
<syntaxhighlight lang="ela">open monad io string list


a'b() = do
a'b() = do
Line 2,457: Line 2,457:
=={{header|Elena}}==
=={{header|Elena}}==
ELENA 5.0 :
ELENA 5.0 :
<syntaxhighlight lang=elena>import extensions;
<syntaxhighlight lang="elena">import extensions;
public program()
public program()
Line 2,468: Line 2,468:


Or more generic solution:
Or more generic solution:
<syntaxhighlight lang=elena>import system'routines;
<syntaxhighlight lang="elena">import system'routines;
import extensions;
import extensions;


Line 2,480: Line 2,480:


=={{header|Elixir}}==
=={{header|Elixir}}==
<syntaxhighlight lang=Elixir>IO.gets("Enter two numbers seperated by a space: ")
<syntaxhighlight lang="elixir">IO.gets("Enter two numbers seperated by a space: ")
|> String.split
|> String.split
|> Enum.map(&String.to_integer(&1))
|> Enum.map(&String.to_integer(&1))
Line 2,487: Line 2,487:


=={{header|Elm}}==
=={{header|Elm}}==
<syntaxhighlight lang=Elm>
<syntaxhighlight lang="elm">
--To write this function directly run cmd
--To write this function directly run cmd
--Type elm-repl to start
--Type elm-repl to start
Line 2,502: Line 2,502:


=={{header|Emacs Lisp}}==
=={{header|Emacs Lisp}}==
<syntaxhighlight lang=lisp>(let* ((input (read-from-minibuffer ""))
<syntaxhighlight lang="lisp">(let* ((input (read-from-minibuffer ""))
(numbers (mapcar #'string-to-number (split-string input)))
(numbers (mapcar #'string-to-number (split-string input)))
(a (car numbers))
(a (car numbers))
Line 2,509: Line 2,509:


=={{header|Emojicode}}==
=={{header|Emojicode}}==
<syntaxhighlight lang=Emojicode>🏁🍇
<syntaxhighlight lang="emojicode">🏁🍇
🆕🔡▶️👂🏼❗️ ➡️ input 💭 Get numbers as input string
🆕🔡▶️👂🏼❗️ ➡️ input 💭 Get numbers as input string
🔫 input 🔤 🔤❗ ➡️ nums 💭 Split numbers by space
🔫 input 🔤 🔤❗ ➡️ nums 💭 Split numbers by space
Line 2,518: Line 2,518:


=={{header|Erlang}}==
=={{header|Erlang}}==
<syntaxhighlight lang=erlang>-module(aplusb).
<syntaxhighlight lang="erlang">-module(aplusb).
-export([start/0]).
-export([start/0]).


Line 2,530: Line 2,530:


=={{header|ERRE}}==
=={{header|ERRE}}==
<syntaxhighlight lang=ERRE>
<syntaxhighlight lang="erre">
PROGRAM SUM2
PROGRAM SUM2


Line 2,547: Line 2,547:
=={{header|Euler Math Toolbox}}==
=={{header|Euler Math Toolbox}}==


<syntaxhighlight lang=Euler Math Toolbox>
<syntaxhighlight lang="euler math toolbox">
>s=lineinput("Two numbers seperated by a blank");
>s=lineinput("Two numbers seperated by a blank");
Two numbers seperated by a blank? >4 5
Two numbers seperated by a blank? >4 5
Line 2,558: Line 2,558:


=={{header|Euphoria}}==
=={{header|Euphoria}}==
<syntaxhighlight lang=euphoria>include get.e
<syntaxhighlight lang="euphoria">include get.e


function snd(sequence s)
function snd(sequence s)
Line 2,574: Line 2,574:
Take any 3 columns of any row or rows. Let's say A1,B1 and C1 are taken. In C1 type in :
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>
<syntaxhighlight lang="excel">
=A1+B1
=A1+B1
</syntaxhighlight>
</syntaxhighlight>
Line 2,580: Line 2,580:
The value of C1 will change as the values of A1 and B1 are changed
The value of C1 will change as the values of A1 and B1 are changed


<lang>1 2 3
<syntaxhighlight lang="text">1 2 3
</syntaxhighlight>
</syntaxhighlight>


=={{header|F Sharp|F#}}==
=={{header|F Sharp|F#}}==
<syntaxhighlight lang=fsharp>open System
<syntaxhighlight lang="fsharp">open System


let SumOf(str : string) =
let SumOf(str : string) =
Line 2,595: Line 2,595:


=={{header|Factor}}==
=={{header|Factor}}==
<syntaxhighlight lang=factor>USING: math.parser splitting ;
<syntaxhighlight lang="factor">USING: math.parser splitting ;
: a+b ( -- )
: a+b ( -- )
readln " " split1
readln " " split1
Line 2,607: Line 2,607:


=={{header|FALSE}}==
=={{header|FALSE}}==
<syntaxhighlight lang=false>[0[^$$'9>'0@>|~]['0-\10*+]#%]n: {read an integer}
<syntaxhighlight lang="false">[0[^$$'9>'0@>|~]['0-\10*+]#%]n: {read an integer}
n;!n;!+.</syntaxhighlight>
n;!n;!+.</syntaxhighlight>


=={{header|Fantom}}==
=={{header|Fantom}}==
<syntaxhighlight lang=fantom>class APlusB
<syntaxhighlight lang="fantom">class APlusB
{
{
public static Void main ()
public static Void main ()
Line 2,625: Line 2,625:
=={{header|FBSL}}==
=={{header|FBSL}}==
Using stdin and stdout
Using stdin and stdout
<syntaxhighlight lang=qbasic>#APPTYPE CONSOLE
<syntaxhighlight lang="qbasic">#APPTYPE CONSOLE


DIM %a, %b
DIM %a, %b
Line 2,634: Line 2,634:


=={{header|Fhidwfe}}==
=={{header|Fhidwfe}}==
<syntaxhighlight lang=Fhidwfe>
<syntaxhighlight lang="fhidwfe">
function listint scanint (num:ptr) {// as of writing, fhidwfe has no builtin int scanning
function listint scanint (num:ptr) {// as of writing, fhidwfe has no builtin int scanning
reset negative
reset negative
Line 2,679: Line 2,679:


=={{header|Fish}}==
=={{header|Fish}}==
<syntaxhighlight lang=Fish>i:o:"-"=?v1$68*-v
<syntaxhighlight lang="fish">i:o:"-"=?v1$68*-v
v >~01-0 >
v >~01-0 >
>i:o:" "=?v68*-$a*+
>i:o:" "=?v68*-$a*+
Line 2,688: Line 2,688:


=={{header|Forth}}==
=={{header|Forth}}==
<syntaxhighlight lang=Forth>pad dup 80 accept evaluate + .</syntaxhighlight>
<syntaxhighlight lang="forth">pad dup 80 accept evaluate + .</syntaxhighlight>


=={{header|Fortran}}==
=={{header|Fortran}}==
<syntaxhighlight lang=fortran>program a_plus_b
<syntaxhighlight lang="fortran">program a_plus_b
implicit none
implicit none
integer :: a,b
integer :: a,b
Line 2,698: Line 2,698:
end program a_plus_b</syntaxhighlight>
end program a_plus_b</syntaxhighlight>
And in Fortran 77
And in Fortran 77
<syntaxhighlight lang=fortran> READ (1,100) I,J
<syntaxhighlight lang="fortran"> READ (1,100) I,J
100 FORMAT(2I5)
100 FORMAT(2I5)
WRITE (2,200) I+J
WRITE (2,200) I+J
Line 2,705: Line 2,705:


=={{header|Free Pascal}}==
=={{header|Free Pascal}}==
<syntaxhighlight lang=pascal>program SUMA;
<syntaxhighlight lang="pascal">program SUMA;
uses
uses
SysUtils;
SysUtils;
Line 2,720: Line 2,720:
=={{header|Frink}}==
=={{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.)
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>
<syntaxhighlight lang="frink">
sum[eval[split[%r/\s+/, input[""]]]]
sum[eval[split[%r/\s+/, input[""]]]]
</syntaxhighlight>
</syntaxhighlight>


=={{header|FunL}}==
=={{header|FunL}}==
<syntaxhighlight lang=funl>println( sum(map(int, readLine().split(' +'))) )</syntaxhighlight>
<syntaxhighlight lang="funl">println( sum(map(int, readLine().split(' +'))) )</syntaxhighlight>


=={{header|Furor}}==
=={{header|Furor}}==
<syntaxhighlight lang=Furor>
<syntaxhighlight lang="furor">
cin sto mystring
cin sto mystring
#s dec mystring @mystring sprintnl
#s dec mystring @mystring sprintnl
Line 2,775: Line 2,775:
=={{header|FutureBasic}}==
=={{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.
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>
<syntaxhighlight lang="futurebasic">
_window = 1
_window = 1
begin enum 1
begin enum 1
Line 2,829: Line 2,829:


=={{header|Gambas}}==
=={{header|Gambas}}==
<syntaxhighlight lang=gambas>Public Sub Main()
<syntaxhighlight lang="gambas">Public Sub Main()
Dim sInput As String = InputBox("Input 2 numbers seperated by a space", "A + B")
Dim sInput As String = InputBox("Input 2 numbers seperated by a space", "A + B")


Line 2,842: Line 2,842:
=={{header|Gastona}}==
=={{header|Gastona}}==
Taking A and B from command line arguments
Taking A and B from command line arguments
<syntaxhighlight lang=gastona>#listix#
<syntaxhighlight lang="gastona">#listix#


<main>
<main>
Line 2,849: Line 2,849:
</syntaxhighlight>
</syntaxhighlight>
Using Graphical interface
Using Graphical interface
<syntaxhighlight lang=gastona>#javaj#
<syntaxhighlight lang="gastona">#javaj#


<layout of main>
<layout of main>
Line 2,867: Line 2,867:


=={{header|Gema}}==
=={{header|Gema}}==
<syntaxhighlight lang=gema><D> <D>=@add{$1;$2}</syntaxhighlight>
<syntaxhighlight lang="gema"><D> <D>=@add{$1;$2}</syntaxhighlight>


=={{header|Genie}}==
=={{header|Genie}}==
<syntaxhighlight lang=genie>[indent=4]
<syntaxhighlight lang="genie">[indent=4]
/*
/*
A+B in Genie
A+B in Genie
Line 2,912: Line 2,912:


=={{header|GML}}==
=={{header|GML}}==
<syntaxhighlight lang=GML>var add, a, b;
<syntaxhighlight lang="gml">var add, a, b;
add = argument0; // get the string with the numbers to add
add = argument0; // get the string with the numbers to add
a = real(string_copy(add, 1, string_pos(" ", add)));
a = real(string_copy(add, 1, string_pos(" ", add)));
Line 2,919: Line 2,919:


=={{header|Go}}==
=={{header|Go}}==
<syntaxhighlight lang=go>package main
<syntaxhighlight lang="go">package main


import "fmt"
import "fmt"
Line 2,930: Line 2,930:


=={{header|Golfscript}}==
=={{header|Golfscript}}==
<syntaxhighlight lang=golfscript>~+</syntaxhighlight>
<syntaxhighlight lang="golfscript">~+</syntaxhighlight>


=={{header|Golo}}==
=={{header|Golo}}==
<syntaxhighlight lang=Golo>#!/usr/bin/env golosh
<syntaxhighlight lang="golo">#!/usr/bin/env golosh
----
----
This module asks for two numbers, adds them, and prints the result.
This module asks for two numbers, adds them, and prints the result.
Line 2,962: Line 2,962:


=={{header|Gosu}}==
=={{header|Gosu}}==
<syntaxhighlight lang=Gosu>
<syntaxhighlight lang="gosu">
uses java.io.InputStreamReader
uses java.io.InputStreamReader
uses java.util.Scanner
uses java.util.Scanner
Line 2,975: Line 2,975:


=={{header|Groovy}}==
=={{header|Groovy}}==
<syntaxhighlight lang=groovy>def abAdder = {
<syntaxhighlight lang="groovy">def abAdder = {
def reader = new Scanner(System.in)
def reader = new Scanner(System.in)
def a = reader.nextInt();
def a = reader.nextInt();
Line 2,986: Line 2,986:
=={{header|GUISS}}==
=={{header|GUISS}}==
We cannot use variables, but we can find the sum of two numbers.Here we add 3 + 2:
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],
<syntaxhighlight lang="guiss">Start,Programs,Accessories,Calculator,Button:3,Button:[plus],
Button:2,Button:[equals]</syntaxhighlight>
Button:2,Button:[equals]</syntaxhighlight>


=={{header|Harbour}}==
=={{header|Harbour}}==
<syntaxhighlight lang=visualfoxpro>PROCEDURE Main()
<syntaxhighlight lang="visualfoxpro">PROCEDURE Main()
LOCAL GetList := {}
LOCAL GetList := {}
LOCAL bValid := { |n| iif(n>-1001, iif(n<1001, .T.,.F.),.F.) }
LOCAL bValid := { |n| iif(n>-1001, iif(n<1001, .T.,.F.),.F.) }
Line 3,009: Line 3,009:


=={{header|Haskell}}==
=={{header|Haskell}}==
<syntaxhighlight lang=haskell>main = print . sum . map read . words =<< getLine</syntaxhighlight>
<syntaxhighlight lang="haskell">main = print . sum . map read . words =<< getLine</syntaxhighlight>


=={{header|hexiscript}}==
=={{header|hexiscript}}==
<syntaxhighlight lang=hexiscript>fun split s delim
<syntaxhighlight lang="hexiscript">fun split s delim
let ret dict 32
let ret dict 32
let l len s
let l len s
Line 3,036: Line 3,036:
=={{header|HicEst}}==
=={{header|HicEst}}==
A and B are input via edit controls with spinners limiting inputs to +-1000.
A and B are input via edit controls with spinners limiting inputs to +-1000.
<syntaxhighlight lang=HicEst>DLG(Edit=A, DNum, MIn=-1000, MAx=1000, E=B, DN, MI=-1000, MA=1000)
<syntaxhighlight 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</syntaxhighlight>
WRITE(Messagebox, Name) A, B, "Sum = ", A+B</syntaxhighlight>


=={{header|Hoon}}==
=={{header|Hoon}}==
<lang>
<syntaxhighlight lang="text">
|= [a=@ud b=@ud] (add a b)
|= [a=@ud b=@ud] (add a b)
</syntaxhighlight>
</syntaxhighlight>
Line 3,060: Line 3,060:


=={{header|Huginn}}==
=={{header|Huginn}}==
<syntaxhighlight lang=huginn>import Algorithms as algo;
<syntaxhighlight lang="huginn">import Algorithms as algo;
import Text as text;
import Text as text;


Line 3,078: Line 3,078:


=={{header|Hy}}==
=={{header|Hy}}==
<syntaxhighlight lang=hy>(print (sum (map int (.split (input)))))</syntaxhighlight>
<syntaxhighlight lang="hy">(print (sum (map int (.split (input)))))</syntaxhighlight>
Alternatively, with the "threading tail" macro:
Alternatively, with the "threading tail" macro:
<syntaxhighlight lang=hy>(->> (input) (.split) (map int) (sum) (print))</syntaxhighlight>
<syntaxhighlight lang="hy">(->> (input) (.split) (map int) (sum) (print))</syntaxhighlight>


=={{header|i}}==
=={{header|i}}==
<syntaxhighlight lang=i>main: print(integer(in(' '))+integer(in('\n'))); ignore</syntaxhighlight>
<syntaxhighlight lang="i">main: print(integer(in(' '))+integer(in('\n'))); ignore</syntaxhighlight>


=={{header|Icon}} and {{header|Unicon}}==
=={{header|Icon}} and {{header|Unicon}}==
<syntaxhighlight lang=icon>procedure main()
<syntaxhighlight lang="icon">procedure main()
numChars := '-'++&digits
numChars := '-'++&digits
read() ? {
read() ? {
Line 3,096: Line 3,096:


=={{header|Idris}}==
=={{header|Idris}}==
<syntaxhighlight lang=idris>main : IO()
<syntaxhighlight lang="idris">main : IO()
main = do
main = do
line <- getLine
line <- getLine
Line 3,103: Line 3,103:
=={{header|J}}==
=={{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:
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> 2+3
<syntaxhighlight lang="j"> 2+3
5</syntaxhighlight>
5</syntaxhighlight>
Next we describe then implement a command line program to add some numbers.
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>.
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>+/". (1!:1(3))-.LF</syntaxhighlight>
<syntaxhighlight lang="j">+/". (1!:1(3))-.LF</syntaxhighlight>
2) Here's a little script, called "a+b.ijs":
2) Here's a little script, called "a+b.ijs":
<syntaxhighlight lang=J>#!/Applications/j602/bin/jconsole
<syntaxhighlight lang="j">#!/Applications/j602/bin/jconsole
echo +/". (1!:1(3))-.LF
echo +/". (1!:1(3))-.LF
exit ''</syntaxhighlight>
exit ''</syntaxhighlight>
3) Here is an execution of the script:
3) Here is an execution of the script:
<syntaxhighlight lang=bash>echo 2 3 | ./a+b.ijs
<syntaxhighlight lang="bash">echo 2 3 | ./a+b.ijs
5</syntaxhighlight>
5</syntaxhighlight>


=={{header|Java}}==
=={{header|Java}}==
<syntaxhighlight lang=java>import java.util.Scanner;
<syntaxhighlight lang="java">import java.util.Scanner;


public class Sum2 {
public class Sum2 {
Line 3,127: Line 3,127:
}</syntaxhighlight>
}</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.
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.*;
<syntaxhighlight lang="java">import java.io.*;
import java.util.*;
import java.util.*;


Line 3,157: Line 3,157:
The following code uses a StreamTokenizer instead of a Scanner.
The following code uses a StreamTokenizer instead of a Scanner.


<syntaxhighlight lang=java>import java.io.*;
<syntaxhighlight lang="java">import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.Charset;


Line 3,176: Line 3,176:




<lang>
<syntaxhighlight lang="text">
grammar aplusb ;
grammar aplusb ;


Line 3,212: Line 3,212:
Client side:
Client side:


<syntaxhighlight lang=html4strict><html>
<syntaxhighlight lang="html4strict"><html>
<body>
<body>
<div id='input'></div>
<div id='input'></div>
Line 3,229: Line 3,229:
Server side (with [http://nodejs.org node.js]):
Server side (with [http://nodejs.org node.js]):


<syntaxhighlight lang=javascript>process.openStdin().on (
<syntaxhighlight lang="javascript">process.openStdin().on (
'data',
'data',
function (line) {
function (line) {
Line 3,249: Line 3,249:
=== ES6 ===
=== ES6 ===
Node.js in a terminal:
Node.js in a terminal:
<syntaxhighlight lang=javascript>process.stdin.on("data", buffer => {
<syntaxhighlight lang="javascript">process.stdin.on("data", buffer => {
console.log(
console.log(
(buffer + "").trim().split(" ").map(Number).reduce((a, v) => a + v, 0)
(buffer + "").trim().split(" ").map(Number).reduce((a, v) => a + v, 0)
Line 3,262: Line 3,262:


=== JScript Windows Script Host Version 5.8 ===
=== JScript Windows Script Host Version 5.8 ===
<syntaxhighlight lang=javascript>var a = WScript.StdIn.ReadLine();
<syntaxhighlight lang="javascript">var a = WScript.StdIn.ReadLine();
var b = WScript.StdIn.ReadLine();
var b = WScript.StdIn.ReadLine();
WSH.echo(a, " + " , b , " = " , Number(a)+Number(b));
WSH.echo(a, " + " , b , " = " , Number(a)+Number(b));
Line 3,269: Line 3,269:
=={{header|Joy}}==
=={{header|Joy}}==
===Console===
===Console===
<syntaxhighlight lang=Joy>get get +.</syntaxhighlight>
<syntaxhighlight lang="joy">get get +.</syntaxhighlight>
===File===
===File===
<syntaxhighlight lang=Joy>"input.txt" include
<syntaxhighlight lang="joy">"input.txt" include
"output.txt" "w" fopen
"output.txt" "w" fopen
get get + fput pop quit.</syntaxhighlight>
get get + fput pop quit.</syntaxhighlight>
Line 3,277: Line 3,277:
=={{header|jq}}==
=={{header|jq}}==
Since the given task is simply to add two numbers, the simplest approach in jq is illustrated by the following transcript:
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
<syntaxhighlight lang="jq">$ jq -s add
3 2
3 2
5 </syntaxhighlight>
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>
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:
def addpairs:
if length < 2 then empty
if length < 2 then empty
Line 3,287: Line 3,287:


addpairs</syntaxhighlight>
addpairs</syntaxhighlight>
For example, here is a transcript that assumes the program is in a file named AB.jq:<syntaxhighlight lang=jq>
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
$ jq -s -f AB.jq
1 2 3 4 5 6
1 2 3 4 5 6
Line 3,295: Line 3,295:


=={{header|Jsish}}==
=={{header|Jsish}}==
<syntaxhighlight lang=javascript>/* A+B in Jsish */
<syntaxhighlight lang="javascript">/* A+B in Jsish */
var line = console.input();
var line = console.input();
var nums = line.match(/^\s*([+-]?[0-9]+)\s+([+-]?[0-9]+)\s*/);
var nums = line.match(/^\s*([+-]?[0-9]+)\s+([+-]?[0-9]+)\s*/);
Line 3,326: Line 3,326:
=={{header|Julia}}==
=={{header|Julia}}==
Run from the command line:
Run from the command line:
<syntaxhighlight lang=julia>input = parse.(Int, split(readline(stdin)))
<syntaxhighlight lang="julia">input = parse.(Int, split(readline(stdin)))
println(stdout, sum(input))</syntaxhighlight>
println(stdout, sum(input))</syntaxhighlight>


Line 3,335: 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.
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> println(parse(Int, readuntil(stdin, ' ')) + parse(Int, readuntil(stdin, '\n')))
<syntaxhighlight lang="julia">julia> println(parse(Int, readuntil(stdin, ' ')) + parse(Int, readuntil(stdin, '\n')))
1 2
1 2
3</syntaxhighlight>
3</syntaxhighlight>


=={{header|K}}==
=={{header|K}}==
<syntaxhighlight lang=K>
<syntaxhighlight lang="k">
split:{(a@&~&/' y=/: a:(0,&x=y)_ x) _dv\: y}
split:{(a@&~&/' y=/: a:(0,&x=y)_ x) _dv\: y}
ab:{+/0$split[0:`;" "]}
ab:{+/0$split[0:`;" "]}
Line 3,349: Line 3,349:


=={{header|Keg}}==
=={{header|Keg}}==
<syntaxhighlight lang=Keg>+.</syntaxhighlight>
<syntaxhighlight lang="keg">+.</syntaxhighlight>
[https://tio.run/##y05N//9fW@//f1MDLjMDAA Try it online!]
[https://tio.run/##y05N//9fW@//f1MDLjMDAA Try it online!]


Or, using flags (<code>-hr</code>):
Or, using flags (<code>-hr</code>):
<syntaxhighlight lang=Keg>+</syntaxhighlight>
<syntaxhighlight lang="keg">+</syntaxhighlight>
[https://tio.run/##y05N//9f@/9/UwMuM4P/uhlFAA Try it online!]
[https://tio.run/##y05N//9f@/9/UwMuM4P/uhlFAA Try it online!]


=={{header|Kite}}==
=={{header|Kite}}==
<syntaxhighlight lang=Kite>#!/usr/bin/kite
<syntaxhighlight lang="kite">#!/usr/bin/kite


import "System.file";
import "System.file";
Line 3,379: Line 3,379:


=={{header|Klong}}==
=={{header|Klong}}==
<syntaxhighlight lang=K>
<syntaxhighlight lang="k">
{(1:$(*x?0c )#x)+1:$(1+*|x?0c )_x}@.rl()
{(1:$(*x?0c )#x)+1:$(1+*|x?0c )_x}@.rl()
2 3
2 3
Line 3,386: Line 3,386:


=={{header|Kotlin}}==
=={{header|Kotlin}}==
<syntaxhighlight lang=scala>// version 1.0.5-2
<syntaxhighlight lang="scala">// version 1.0.5-2


fun main(args: Array<String>) {
fun main(args: Array<String>) {
Line 3,422: Line 3,422:


=={{header|KQL}}==
=={{header|KQL}}==
<syntaxhighlight lang=KQL>datatable(Input:string)[
<syntaxhighlight lang="kql">datatable(Input:string)[
'2 2',
'2 2',
'3 2'
'3 2'
Line 3,430: Line 3,430:


=={{header|L++}}==
=={{header|L++}}==
<syntaxhighlight lang=lisp>(main
<syntaxhighlight lang="lisp">(main
(decl int a)
(decl int a)
(decl int b)
(decl int b)
Line 3,437: Line 3,437:


=={{header|Lambdatalk}}==
=={{header|Lambdatalk}}==
<syntaxhighlight lang=scheme>
<syntaxhighlight lang="scheme">
Lambdatalk works in a wiki, lambdatank.
Lambdatalk works in a wiki, lambdatank.


Line 3,472: Line 3,472:


=={{header|Lang5}}==
=={{header|Lang5}}==
<syntaxhighlight lang=lang5>read read + .
<syntaxhighlight lang="lang5">read read + .


read " " split expand drop + .</syntaxhighlight>
read " " split expand drop + .</syntaxhighlight>


=={{header|Lasso}}==
=={{header|Lasso}}==
<syntaxhighlight lang=lb>[a + b]</syntaxhighlight>
<syntaxhighlight lang="lb">[a + b]</syntaxhighlight>


=={{header|LIL}}==
=={{header|LIL}}==
<syntaxhighlight lang=tcl># A+B, in LIL
<syntaxhighlight lang="tcl"># A+B, in LIL
# Requires lil shell readline routine
# Requires lil shell readline routine
set in [readline]
set in [readline]
Line 3,494: Line 3,494:


=={{header|Lisaac}}==
=={{header|Lisaac}}==
<syntaxhighlight lang=lisaac>Section Header
<syntaxhighlight lang="lisaac">Section Header
+ name := A_PLUS_B
+ name := A_PLUS_B


Line 3,502: Line 3,502:


=={{header|Little}}==
=={{header|Little}}==
<syntaxhighlight lang=c>void main() {
<syntaxhighlight lang="c">void main() {
string a, b;
string a, b;
scan(gets(stdin), "%d %d", &a, &b);
scan(gets(stdin), "%d %d", &a, &b);
Line 3,514: Line 3,514:


'''Assembly'''
'''Assembly'''
<syntaxhighlight lang=Little Man Computer> INP
<syntaxhighlight lang="little man computer"> INP
STA 99
STA 99
INP
INP
Line 3,523: Line 3,523:


'''Machine code'''
'''Machine code'''
<syntaxhighlight lang=Little Man Computer>00 INP
<syntaxhighlight lang="little man computer">00 INP
01 STA 99
01 STA 99
02 INP
02 INP
Line 3,532: Line 3,532:
=={{header|LiveCode}}==
=={{header|LiveCode}}==
Using Livecode Server script
Using Livecode Server script
<syntaxhighlight lang=LiveCode><?lc
<syntaxhighlight lang="livecode"><?lc
if isNumber($0) and isNumber($1) then
if isNumber($0) and isNumber($1) then
put $0 + $1
put $0 + $1
Line 3,541: Line 3,541:


A graphical version using an input dialog
A graphical version using an input dialog
<syntaxhighlight lang=LiveCode>on mouseUp
<syntaxhighlight lang="livecode">on mouseUp
ask "Enter two numbers"
ask "Enter two numbers"
set itemdelimiter to space
set itemdelimiter to space
Line 3,553: Line 3,553:


=={{header|Logo}}==
=={{header|Logo}}==
<syntaxhighlight lang=logo>show apply "sum readlist</syntaxhighlight>
<syntaxhighlight lang="logo">show apply "sum readlist</syntaxhighlight>


=={{header|Lua}}==
=={{header|Lua}}==
<syntaxhighlight lang=Lua>a,b = io.read("*number", "*number")
<syntaxhighlight lang="lua">a,b = io.read("*number", "*number")
print(a+b)</syntaxhighlight>
print(a+b)</syntaxhighlight>


=={{header|M2000 Interpreter}}==
=={{header|M2000 Interpreter}}==
<lang>Def Range(X%)=Abs(X%)<=1000
<syntaxhighlight lang="text">Def Range(X%)=Abs(X%)<=1000
Do {
Do {
Input A%, B%
Input A%, B%
Line 3,567: Line 3,567:


=={{header|M4}}==
=={{header|M4}}==
<syntaxhighlight lang=M4> define(`sumstr', `eval(patsubst(`$1',` ',`+'))')
<syntaxhighlight lang="m4"> define(`sumstr', `eval(patsubst(`$1',` ',`+'))')


sumstr(1 2)
sumstr(1 2)
Line 3,573: Line 3,573:


=={{header|Maple}}==
=={{header|Maple}}==
<syntaxhighlight lang=maple> convert( scanf( "%d %d" ), '`+`' );
<syntaxhighlight lang="maple"> convert( scanf( "%d %d" ), '`+`' );
23 34
23 34
57</syntaxhighlight>
57</syntaxhighlight>
Line 3,579: Line 3,579:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
Interactive in a notebook
Interactive in a notebook
<syntaxhighlight lang=Mathematica>Input[] + Input[]</syntaxhighlight>
<syntaxhighlight lang="mathematica">Input[] + Input[]</syntaxhighlight>


=={{header|MATLAB}} / {{header|Octave}}==
=={{header|MATLAB}} / {{header|Octave}}==
<syntaxhighlight lang=MATLAB>function sumOfInputs = APlusB()
<syntaxhighlight lang="matlab">function sumOfInputs = APlusB()
inputStream = input('Enter two numbers, separated by a space: ', 's');
inputStream = input('Enter two numbers, separated by a space: ', 's');
numbers = str2num(inputStream); %#ok<ST2NM>
numbers = str2num(inputStream); %#ok<ST2NM>
Line 3,593: Line 3,593:
=={{header|Maude}}==
=={{header|Maude}}==
===Built-in===
===Built-in===
<syntaxhighlight lang=Maude>
<syntaxhighlight lang="maude">
red 3 + 4 .
red 3 + 4 .
</syntaxhighlight>
</syntaxhighlight>
===With restrictions===
===With restrictions===
<syntaxhighlight lang=Maude>
<syntaxhighlight lang="maude">
fmod ADD is
fmod ADD is


Line 3,613: Line 3,613:


=={{header|Maxima}}==
=={{header|Maxima}}==
<lang>in_stream: openr("/dev/stdin");
<syntaxhighlight lang="text">in_stream: openr("/dev/stdin");
unless (line: readline(in_stream), line=false) do (
unless (line: readline(in_stream), line=false) do (
q: map('parse_string, split(line, " ")),
q: map('parse_string, split(line, " ")),
Line 3,622: Line 3,622:


=={{header|Mercury}}==
=={{header|Mercury}}==
<lang>:- module a_plus_b.
<syntaxhighlight lang="text">:- module a_plus_b.
:- interface.
:- interface.


Line 3,645: Line 3,645:
=={{header|min}}==
=={{header|min}}==
{{works with|min|0.19.3}}
{{works with|min|0.19.3}}
<syntaxhighlight lang=min>gets " " split 'bool filter 'int map sum puts!</syntaxhighlight>
<syntaxhighlight lang="min">gets " " split 'bool filter 'int map sum puts!</syntaxhighlight>


=={{header|MiniScript}}==
=={{header|MiniScript}}==
The <code>input</code> intrinsic in MiniScript isn't available in all implementations, so we've just hard-coded the input here:
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>s = " 2 3 "
<syntaxhighlight lang="miniscript">s = " 2 3 "
fields = s.split
fields = s.split
for i in range(fields.len-1, 0)
for i in range(fields.len-1, 0)
Line 3,664: Line 3,664:


=={{header|mIRC Scripting Language}}==
=={{header|mIRC Scripting Language}}==
<syntaxhighlight lang=mirc>alias a+b {
<syntaxhighlight lang="mirc">alias a+b {
echo -ag $calc($1 + $2)
echo -ag $calc($1 + $2)
}</syntaxhighlight>
}</syntaxhighlight>
Line 3,675: Line 3,675:
=={{header|ML/I}}==
=={{header|ML/I}}==
The two numbers are read from 'standard input' or its equivalent.
The two numbers are read from 'standard input' or its equivalent.
<syntaxhighlight lang=ML/I>MCSKIP "WITH" NL
<syntaxhighlight lang="ml/i">MCSKIP "WITH" NL
"" A+B
"" A+B
"" assumes macros on input stream 1, terminal on stream 2
"" assumes macros on input stream 1, terminal on stream 2
Line 3,690: Line 3,690:


=={{header|Modula-2}}==
=={{header|Modula-2}}==
<syntaxhighlight lang=modula2>MODULE ab;
<syntaxhighlight lang="modula2">MODULE ab;


IMPORT InOut;
IMPORT InOut;
Line 3,704: Line 3,704:


=={{header|Modula-3}}==
=={{header|Modula-3}}==
<syntaxhighlight lang=modula3>MODULE Ab EXPORTS Main;
<syntaxhighlight lang="modula3">MODULE Ab EXPORTS Main;


IMPORT IO;
IMPORT IO;
Line 3,722: Line 3,722:


=={{header|MoonScript}}==
=={{header|MoonScript}}==
<syntaxhighlight lang=moonscript>a,b = io.read '*number','*number'
<syntaxhighlight lang="moonscript">a,b = io.read '*number','*number'
print a + b</syntaxhighlight>
print a + b</syntaxhighlight>


=={{header|MUMPS}}==
=={{header|MUMPS}}==
<syntaxhighlight lang=MUMPS>ANB
<syntaxhighlight lang="mumps">ANB
NEW A,B,T,S
NEW A,B,T,S
READ !,"Input two integers between -1000 and 1000, separated by a space: ",S
READ !,"Input two integers between -1000 and 1000, separated by a space: ",S
Line 3,736: Line 3,736:


=={{header|Nanoquery}}==
=={{header|Nanoquery}}==
<syntaxhighlight lang=Nanoquery>// get a line of input
<syntaxhighlight lang="nanoquery">// get a line of input
line = input()
line = input()
Line 3,746: Line 3,746:


=={{header|Neko}}==
=={{header|Neko}}==
<syntaxhighlight lang=ActionScript>/**
<syntaxhighlight lang="actionscript">/**
A+B, Rosetta Code, in Neko
A+B, Rosetta Code, in Neko
Tectonics:
Tectonics:
Line 3,822: Line 3,822:
=={{header|Nemerle}}==
=={{header|Nemerle}}==
{{trans|C#}}
{{trans|C#}}
<syntaxhighlight lang=Nemerle>using System;
<syntaxhighlight lang="nemerle">using System;
using System.Console;
using System.Console;
using System.Linq;
using System.Linq;
Line 3,835: Line 3,835:


=={{header|NetRexx}}==
=={{header|NetRexx}}==
<syntaxhighlight lang=NetRexx>/* NetRexx */
<syntaxhighlight lang="netrexx">/* NetRexx */


options replace format comments java symbols binary
options replace format comments java symbols binary
Line 3,843: Line 3,843:


=={{header|newLISP}}==
=={{header|newLISP}}==
<syntaxhighlight lang=newLISP>(println (apply + (map int (parse (read-line)))))</syntaxhighlight>
<syntaxhighlight lang="newlisp">(println (apply + (map int (parse (read-line)))))</syntaxhighlight>


=={{header|Nim}}==
=={{header|Nim}}==
A+B:
A+B:
<syntaxhighlight lang=nim>
<syntaxhighlight lang="nim">
# Takes 2 inputs of Floats and adds them (which is not correct for the exercise, will revisit, Thank you
# Takes 2 inputs of Floats and adds them (which is not correct for the exercise, will revisit, Thank you


Line 3,875: Line 3,875:
=={{header|Nit}}==
=={{header|Nit}}==
Generic non-robust version (source: [https://github.com/nitlang/nit/blob/master/examples/rosettacode/ab.nit the Nit’s official repository]):
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
<syntaxhighlight lang="nit">module ab


var words = gets.split(" ")
var words = gets.split(" ")
Line 3,885: Line 3,885:


=={{header|NS-HUBASIC}}==
=={{header|NS-HUBASIC}}==
<syntaxhighlight lang=NS-HUBASIC>10 INPUT "ENTER NUMBER A: ",A
<syntaxhighlight lang="ns-hubasic">10 INPUT "ENTER NUMBER A: ",A
20 INPUT "ENTER NUMBER B: ",B
20 INPUT "ENTER NUMBER B: ",B
30 PRINT A+B</syntaxhighlight>
30 PRINT A+B</syntaxhighlight>
Line 3,891: Line 3,891:
=={{header|Nyquist}}==
=={{header|Nyquist}}==
===SAL Syntax===
===SAL Syntax===
<syntaxhighlight lang=Nyquist>;nyquist plug-in
<syntaxhighlight lang="nyquist">;nyquist plug-in
;version 1
;version 1
;type tool
;type tool
Line 3,905: Line 3,905:


===Audacity plug-in (SAL syntax)===
===Audacity plug-in (SAL syntax)===
<syntaxhighlight lang=Nyquist>;nyquist plug-in
<syntaxhighlight lang="nyquist">;nyquist plug-in
;version 1
;version 1
;type tool
;type tool
Line 3,919: Line 3,919:


=={{header|Oberon-2}}==
=={{header|Oberon-2}}==
<syntaxhighlight lang=oberon2>MODULE ab;
<syntaxhighlight lang="oberon2">MODULE ab;


IMPORT In, Out;
IMPORT In, Out;
Line 3,938: Line 3,938:


=={{header|Objeck}}==
=={{header|Objeck}}==
<syntaxhighlight lang=objeck>bundle Default {
<syntaxhighlight lang="objeck">bundle Default {
class Vander {
class Vander {
function : Main(args : String[]) ~ Nil {
function : Main(args : String[]) ~ Nil {
Line 3,950: Line 3,950:


=={{header|OCaml}}==
=={{header|OCaml}}==
<syntaxhighlight lang=ocaml>Scanf.scanf "%d %d" (fun a b -> Printf.printf "%d\n" (a + b))</syntaxhighlight>
<syntaxhighlight lang="ocaml">Scanf.scanf "%d %d" (fun a b -> Printf.printf "%d\n" (a + b))</syntaxhighlight>


=={{header|Oforth}}==
=={{header|Oforth}}==
Line 3,956: Line 3,956:
Works with any number of integers separated by a space.
Works with any number of integers separated by a space.


<syntaxhighlight lang=Oforth>import: mapping
<syntaxhighlight lang="oforth">import: mapping


System.Console accept words map( #>integer) reduce( #+ ) printcr .</syntaxhighlight>
System.Console accept words map( #>integer) reduce( #+ ) printcr .</syntaxhighlight>
Line 3,963: Line 3,963:
Note: input data must be separated by newline ([Enter] key press).
Note: input data must be separated by newline ([Enter] key press).


<syntaxhighlight lang=ol>; simplest
<syntaxhighlight lang="ol">; simplest
(+ (read) (read))
(+ (read) (read))


Line 3,979: Line 3,979:
=={{header|Onyx}}==
=={{header|Onyx}}==


<syntaxhighlight lang=onyx>$Prompt {
<syntaxhighlight lang="onyx">$Prompt {
`\nEnter two numbers between -1000 and +1000,\nseparated by a space: ' print flush
`\nEnter two numbers between -1000 and +1000,\nseparated by a space: ' print flush
} def
} def
Line 4,008: Line 4,008:
===version 1===
===version 1===
{{trans|REXX}}
{{trans|REXX}}
<syntaxhighlight lang=oorexx>Numeric digits 1000 /*just in case the user gets ka-razy. */
<syntaxhighlight lang="oorexx">Numeric digits 1000 /*just in case the user gets ka-razy. */
Say 'enter some numbers to be summed:'
Say 'enter some numbers to be summed:'
parse pull y
parse pull y
Line 4,032: Line 4,032:
===version 2===
===version 2===
extend for negative numbers
extend for negative numbers
<syntaxhighlight lang=oorexx>Numeric digits 1000
<syntaxhighlight lang="oorexx">Numeric digits 1000
Say 'enter some numbers to be summed:'
Say 'enter some numbers to be summed:'
parse pull y
parse pull y
Line 4,055: Line 4,055:


=={{header|OpenEdge/Progress}}==
=={{header|OpenEdge/Progress}}==
<syntaxhighlight lang=progress>DEFINE VARIABLE a AS INTEGER NO-UNDO FORMAT "->>>9".
<syntaxhighlight lang="progress">DEFINE VARIABLE a AS INTEGER NO-UNDO FORMAT "->>>9".
DEFINE VARIABLE b AS INTEGER NO-UNDO FORMAT "->>>9".
DEFINE VARIABLE b AS INTEGER NO-UNDO FORMAT "->>>9".


Line 4,070: Line 4,070:
=={{header|Openscad}}==
=={{header|Openscad}}==
There is no means of run-time input in Openscad
There is no means of run-time input in Openscad
<syntaxhighlight lang=openscad>
<syntaxhighlight lang="openscad">
a = 5 + 4;
a = 5 + 4;
echo (a);
echo (a);
Line 4,079: 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))'''.
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>
<syntaxhighlight lang="order">
#define ORDER_PP_DEF_1int_is_positive \
#define ORDER_PP_DEF_1int_is_positive \
ORDER_PP_FN(8fn(8X, 8is_0(8tuple_at_0(8X))))
ORDER_PP_FN(8fn(8X, 8is_0(8tuple_at_0(8X))))
Line 4,119: Line 4,119:


=={{header|Oxygene}}==
=={{header|Oxygene}}==
<syntaxhighlight lang=oxygene>
<syntaxhighlight lang="oxygene">
// Sum 2 integers read fron standard input
// Sum 2 integers read fron standard input
//
//
Line 4,161: Line 4,161:


=={{header|Oz}}==
=={{header|Oz}}==
<syntaxhighlight lang=oz>declare
<syntaxhighlight lang="oz">declare
class TextFile from Open.file Open.text end
class TextFile from Open.file Open.text end


Line 4,174: Line 4,174:
=={{header|PARI/GP}}==
=={{header|PARI/GP}}==
User input:
User input:
<syntaxhighlight lang=parigp>input()+input()</syntaxhighlight>
<syntaxhighlight lang="parigp">input()+input()</syntaxhighlight>
File input:
File input:
<syntaxhighlight lang=parigp>read("file1")+read("file2")</syntaxhighlight>
<syntaxhighlight lang="parigp">read("file1")+read("file2")</syntaxhighlight>


=={{header|Pascal}}==
=={{header|Pascal}}==
<syntaxhighlight lang=pascal>var
<syntaxhighlight lang="pascal">var
a, b: integer;
a, b: integer;
begin
begin
Line 4,186: Line 4,186:
end.</syntaxhighlight>
end.</syntaxhighlight>
Same with input from file <tt>input.txt</tt> and output from file <tt>output.txt</tt>.
Same with input from file <tt>input.txt</tt> and output from file <tt>output.txt</tt>.
<syntaxhighlight lang=pascal>var
<syntaxhighlight lang="pascal">var
a, b: integer;
a, b: integer;
begin
begin
Line 4,197: Line 4,197:
end.</syntaxhighlight>
end.</syntaxhighlight>
===Version 2. Following the rules===
===Version 2. Following the rules===
<syntaxhighlight lang=pascal>{ Task: A + B
<syntaxhighlight lang="pascal">{ Task: A + B
Sum of A + B while A, B >= -1000 and A,B <= 1000
Sum of A + B while A, B >= -1000 and A,B <= 1000
Author: Sinuhe Masan (2019) }
Author: Sinuhe Masan (2019) }
Line 4,217: Line 4,217:


=={{header|Perl}}==
=={{header|Perl}}==
<syntaxhighlight lang=Perl>my ($a,$b) = split(' ', scalar(<STDIN>));
<syntaxhighlight lang="perl">my ($a,$b) = split(' ', scalar(<STDIN>));
print "$a $b " . ($a + $b) . "\n";</syntaxhighlight>
print "$a $b " . ($a + $b) . "\n";</syntaxhighlight>


=== using the List::Util module ===
=== using the List::Util module ===
<syntaxhighlight lang=Perl>say sum split /\s+/, scalar <STDIN>;</syntaxhighlight>
<syntaxhighlight lang="perl">say sum split /\s+/, scalar <STDIN>;</syntaxhighlight>


=={{header|Phix}}==
=={{header|Phix}}==
<!--<syntaxhighlight lang=Phix>-->
<!--<syntaxhighlight lang="phix">-->
<span style="color: #000080;font-style:italic;">-- demo\rosetta\AplusB.exw</span>
<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>
<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,242: Line 4,242:
=== GUI version ===
=== GUI version ===
<small>(The above console version is now just a comment in the distributed file.)</small>
<small>(The above console version is now just a comment in the distributed file.)</small>
<!--<syntaxhighlight lang=Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">-- demo\rosetta\AplusB.exw</span>
<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>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
Line 4,278: Line 4,278:


=={{header|Phixmonti}}==
=={{header|Phixmonti}}==
<syntaxhighlight lang=Phixmonti>/# Rosetta Code problem: http://rosettacode.org/wiki/A+B
<syntaxhighlight lang="phixmonti">/# Rosetta Code problem: http://rosettacode.org/wiki/A+B
by Galileo, 05/2022 #/
by Galileo, 05/2022 #/


Line 4,301: Line 4,301:


=={{header|PHP}}==
=={{header|PHP}}==
<syntaxhighlight lang=php>fscanf(STDIN, "%d %d\n", $a, $b); //Reads 2 numbers from STDIN
<syntaxhighlight lang="php">fscanf(STDIN, "%d %d\n", $a, $b); //Reads 2 numbers from STDIN
echo ($a + $b) . "\n";</syntaxhighlight>
echo ($a + $b) . "\n";</syntaxhighlight>
<syntaxhighlight lang=php>$in = fopen("input.dat", "r");
<syntaxhighlight lang="php">$in = fopen("input.dat", "r");
fscanf($in, "%d %d\n", $a, $b); //Reads 2 numbers from file $in
fscanf($in, "%d %d\n", $a, $b); //Reads 2 numbers from file $in
fclose($in);
fclose($in);
Line 4,312: Line 4,312:


=={{header|Picat}}==
=={{header|Picat}}==
<syntaxhighlight lang=Picat>
<syntaxhighlight lang="picat">
go =>
go =>
println("Write two integers (and CR)"),
println("Write two integers (and CR)"),
Line 4,333: Line 4,333:


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
<syntaxhighlight lang=PicoLisp>(+ (read) (read))
<syntaxhighlight lang="picolisp">(+ (read) (read))
3 4
3 4
-> 7</syntaxhighlight>
-> 7</syntaxhighlight>
Line 4,340: Line 4,340:
[[File:Piet A+B.png]]
[[File:Piet A+B.png]]
The code is fairly straightforward. The individual commands are as follows:
The code is fairly straightforward. The individual commands are as follows:
<syntaxhighlight lang=text>in(num)
<syntaxhighlight lang="text">in(num)
in(num)
in(num)
add
add
Line 4,346: Line 4,346:


=={{header|Pike}}==
=={{header|Pike}}==
<syntaxhighlight lang=Pike>string line = Stdio.stdin->gets();
<syntaxhighlight lang="pike">string line = Stdio.stdin->gets();
sscanf(line, "%d %d", int a, int b);
sscanf(line, "%d %d", int a, int b);
write(a+b +"\n");</syntaxhighlight>
write(a+b +"\n");</syntaxhighlight>


=={{header|PL/I}}==
=={{header|PL/I}}==
<syntaxhighlight lang=pli>get (a, b);
<syntaxhighlight lang="pli">get (a, b);
put (a+b);</syntaxhighlight>
put (a+b);</syntaxhighlight>


=={{header|Pony}}==
=={{header|Pony}}==
<syntaxhighlight lang=pony>
<syntaxhighlight lang="pony">
actor Main
actor Main
let _env:Env
let _env:Env
Line 4,384: Line 4,384:


=={{header|PostScript}}==
=={{header|PostScript}}==
<syntaxhighlight lang=postscript>(%stdin) (r) file % get stdin
<syntaxhighlight lang="postscript">(%stdin) (r) file % get stdin
dup
dup
token pop % read A
token pop % read A
Line 4,393: Line 4,393:


=={{header|Potion}}==
=={{header|Potion}}==
<syntaxhighlight lang=potion># The numbers are entered, piped, or redirected in via STDIN and the format is proper (i.e., "%d %d").
<syntaxhighlight lang="potion"># The numbers are entered, piped, or redirected in via STDIN and the format is proper (i.e., "%d %d").
input = read
input = read
i = 0
i = 0
Line 4,408: Line 4,408:


=={{header|PowerShell}}==
=={{header|PowerShell}}==
<syntaxhighlight lang=powershell>$a,$b = -split "$input"
<syntaxhighlight lang="powershell">$a,$b = -split "$input"
[int]$a + [int]$b</syntaxhighlight>
[int]$a + [int]$b</syntaxhighlight>
This solution does not work interactively, while the following ''only'' works interactively:
This solution does not work interactively, while the following ''only'' works interactively:
<syntaxhighlight lang=powershell>$a,$b = -split (Read-Host)
<syntaxhighlight lang="powershell">$a,$b = -split (Read-Host)
[int]$a + [int]$b</syntaxhighlight>
[int]$a + [int]$b</syntaxhighlight>


I think this works better and doesn't require string input (following the task closer):
I think this works better and doesn't require string input (following the task closer):
<syntaxhighlight lang=powershell>filter add {
<syntaxhighlight lang="powershell">filter add {
return [int]$args[0] + [int]$args[1]
return [int]$args[0] + [int]$args[1]
}</syntaxhighlight>
}</syntaxhighlight>


Can be called in one line with
Can be called in one line with
<syntaxhighlight lang=powershell>add 2 3</syntaxhighlight>
<syntaxhighlight lang="powershell">add 2 3</syntaxhighlight>


=={{header|Processing}}==
=={{header|Processing}}==
===Rudimentary User Interface===
===Rudimentary User Interface===
Click on either side to add 1 to its value.
Click on either side to add 1 to its value.
<syntaxhighlight lang=Processing>int a = 0;
<syntaxhighlight lang="processing">int a = 0;
int b = 0;
int b = 0;


Line 4,455: Line 4,455:
=={{header|ProDOS}}==
=={{header|ProDOS}}==
With the math module:
With the math module:
<syntaxhighlight lang=ProDOS>editvar /newvar /value=a /title=Enter an integer:
<syntaxhighlight lang="prodos">editvar /newvar /value=a /title=Enter an integer:
editvar /newvar /value=b /title=Enter another integer:
editvar /newvar /value=b /title=Enter another integer:
editvar /newvar /value=c
editvar /newvar /value=c
Line 4,461: Line 4,461:
printline -c- </syntaxhighlight>
printline -c- </syntaxhighlight>
Without the math module:
Without the math module:
<syntaxhighlight lang=ProDOS>editvar /newvar /value=a /title=Enter an integer:
<syntaxhighlight lang="prodos">editvar /newvar /value=a /title=Enter an integer:
editvar /newvar /value=b /title=Enter another integer:
editvar /newvar /value=b /title=Enter another integer:
editvar /newvar /value=c=-a-+-b-
editvar /newvar /value=c=-a-+-b-
Line 4,468: Line 4,468:
=={{header|Prolog}}==
=={{header|Prolog}}==
{{Works with|SWI-Prolog}}
{{Works with|SWI-Prolog}}
<syntaxhighlight lang=Prolog>plus :-
<syntaxhighlight lang="prolog">plus :-
read_line_to_codes(user_input,X),
read_line_to_codes(user_input,X),
atom_codes(A, X),
atom_codes(A, X),
Line 4,476: Line 4,476:
write(N).</syntaxhighlight>
write(N).</syntaxhighlight>
output :
output :
<syntaxhighlight lang=Prolog>?- plus.
<syntaxhighlight lang="prolog">?- plus.
|: 4 5
|: 4 5
9
9
Line 4,482: Line 4,482:


=={{header|Pure}}==
=={{header|Pure}}==
<syntaxhighlight lang=pure>using system;
<syntaxhighlight lang="pure">using system;
printf "%d\n" (x+y) when x,y = scanf "%d %d" end;</syntaxhighlight>
printf "%d\n" (x+y) when x,y = scanf "%d %d" end;</syntaxhighlight>


=={{header|PureBasic}}==
=={{header|PureBasic}}==
===Console===
===Console===
<syntaxhighlight lang=PureBasic>x$=Input()
<syntaxhighlight lang="purebasic">x$=Input()
a=Val(StringField(x$,1," "))
a=Val(StringField(x$,1," "))
b=Val(StringField(x$,2," "))
b=Val(StringField(x$,2," "))
PrintN(str(a+b))</syntaxhighlight>
PrintN(str(a+b))</syntaxhighlight>
===File===
===File===
<syntaxhighlight lang=PureBasic>If ReadFile(0,"in.txt")
<syntaxhighlight lang="purebasic">If ReadFile(0,"in.txt")
x$=ReadString(0)
x$=ReadString(0)
a=Val(StringField(x$,1," "))
a=Val(StringField(x$,1," "))
Line 4,510: 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.
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
<syntaxhighlight lang="python">try: raw_input
except: raw_input = input
except: raw_input = input


Line 4,517: Line 4,517:
===File===
===File===
For Python 2.X and 3.X taking input from stdin stream which can be redirected to be file input under Unix
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
<syntaxhighlight lang="python">import sys


for line in sys.stdin:
for line in sys.stdin:
Line 4,523: Line 4,523:


===Console, Python 3 only===
===Console, Python 3 only===
<syntaxhighlight lang=python>a = int(input("First number: "))
<syntaxhighlight lang="python">a = int(input("First number: "))
b = int(input("Second number: "))
b = int(input("Second number: "))
print("Result:", a+b)</syntaxhighlight>
print("Result:", a+b)</syntaxhighlight>


=={{header|QB64}}==
=={{header|QB64}}==
<syntaxhighlight lang=QB64>DIM a AS INTEGER, b AS INTEGER
<syntaxhighlight lang="qb64">DIM a AS INTEGER, b AS INTEGER
DIM c AS LONG
DIM c AS LONG
INPUT "Enter A: ", a
INPUT "Enter A: ", a
Line 4,544: Line 4,544:
** Integers between -1000 and +1000.
** Integers between -1000 and +1000.
<syntaxhighlight lang=qbasic>START:
<syntaxhighlight lang="qbasic">START:
PRINT "Enter two integers between -1000 and +1000 separated by at least one space: "
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.
INPUT "> "; n$ ' | Enter two numbers with at least one space between.
Line 4,571: Line 4,571:


=={{header|Quite BASIC}}==
=={{header|Quite BASIC}}==
<syntaxhighlight lang=Quite BASIC>10 input "Enter number A: ";a
<syntaxhighlight lang="quite basic">10 input "Enter number A: ";a
20 input "Enter number B: ";b
20 input "Enter number B: ";b
30 print a+b</syntaxhighlight>
30 print a+b</syntaxhighlight>


=={{header|R}}==
=={{header|R}}==
<syntaxhighlight lang=r>sum(scan("", numeric(0), 2))</syntaxhighlight>
<syntaxhighlight lang="r">sum(scan("", numeric(0), 2))</syntaxhighlight>


=={{header|Ra}}==
=={{header|Ra}}==
<syntaxhighlight lang=Ra>
<syntaxhighlight lang="ra">
class Sum
class Sum
**Adds two given integers**
**Adds two given integers**
Line 4,609: Line 4,609:
=={{header|Racket}}==
=={{header|Racket}}==


<syntaxhighlight lang=racket>
<syntaxhighlight lang="racket">
#lang racket
#lang racket
(+ (read) (read))
(+ (read) (read))
Line 4,615: Line 4,615:


Or, with additional error checking:
Or, with additional error checking:
<syntaxhighlight lang=racket>
<syntaxhighlight lang="racket">
#lang racket
#lang racket
(define a (read))
(define a (read))
Line 4,629: Line 4,629:


Short version with very little "line noise":
Short version with very little "line noise":
<syntaxhighlight lang=perl6>get.words.sum.say;</syntaxhighlight>
<syntaxhighlight lang="raku" line>get.words.sum.say;</syntaxhighlight>
Reduction operator <code>[+]</code>, and <code>say</code> as a function:
Reduction operator <code>[+]</code>, and <code>say</code> as a function:
<syntaxhighlight lang=perl6>say [+] get.words;</syntaxhighlight>
<syntaxhighlight lang="raku" line>say [+] get.words;</syntaxhighlight>
Long version:
Long version:
<syntaxhighlight lang=perl6>my ($a, $b) = $*IN.get.split(" ");
<syntaxhighlight lang="raku" line>my ($a, $b) = $*IN.get.split(" ");
say $a + $b;</syntaxhighlight>
say $a + $b;</syntaxhighlight>


=={{header|REBOL}}==
=={{header|REBOL}}==
<syntaxhighlight lang=rebol>forever [x: load input print x/1 + x/2]</syntaxhighlight>
<syntaxhighlight lang="rebol">forever [x: load input print x/1 + x/2]</syntaxhighlight>
{{Out}}
{{Out}}
<pre>1 2
<pre>1 2
Line 4,647: Line 4,647:


=={{header|Red}}==
=={{header|Red}}==
<syntaxhighlight lang=Red>x: load input print x/1 + x/2</syntaxhighlight>
<syntaxhighlight lang="red">x: load input print x/1 + x/2</syntaxhighlight>
{{Out}}
{{Out}}
<pre>1 2
<pre>1 2
Line 4,657: Line 4,657:


Alternative implementations:
Alternative implementations:
<syntaxhighlight lang=Red>print (first x: load input) + x/2</syntaxhighlight>
<syntaxhighlight lang="red">print (first x: load input) + x/2</syntaxhighlight>
<syntaxhighlight lang=Red>print head insert load input 'add</syntaxhighlight>
<syntaxhighlight lang="red">print head insert load input 'add</syntaxhighlight>
<syntaxhighlight lang=Red>print load replace input " " " + "</syntaxhighlight>
<syntaxhighlight lang="red">print load replace input " " " + "</syntaxhighlight>


=={{header|Relation}}==
=={{header|Relation}}==
<syntaxhighlight lang=Relation>
<syntaxhighlight lang="relation">
set input = "2 2"
set input = "2 2"
set a = regexreplace(input,"^(-?\d+)\s+(-?\d+)+$","$1")
set a = regexreplace(input,"^(-?\d+)\s+(-?\d+)+$","$1")
Line 4,670: Line 4,670:


=={{header|Retro}}==
=={{header|Retro}}==
<syntaxhighlight lang=Retro>:try ("-n) s:get s:to-number s:get s:to-number + n:put ;</syntaxhighlight>
<syntaxhighlight lang="retro">:try ("-n) s:get s:to-number s:get s:to-number + n:put ;</syntaxhighlight>
<syntaxhighlight lang=Retro>try
<syntaxhighlight lang="retro">try
1
1
2</syntaxhighlight>
2</syntaxhighlight>
Line 4,678: Line 4,678:
===version 1, unnormalized===
===version 1, unnormalized===
The numbers can be any valid REXX number (integer, fixed point decimal, floating point (with exponential notation, ···).
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.*/
<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.*/
parse pull a b /*obtain two numbers from input stream.*/
say a+b /*display the sum to the terminal. */
say a+b /*display the sum to the terminal. */
Line 4,690: Line 4,690:


Dividing by one normalizes the number.
Dividing by one normalizes the number.
<syntaxhighlight lang=rexx>/*REXX program obtains two numbers from the input stream (the console), shows their sum.*/
<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.*/
parse pull a b /*obtain two numbers from input stream.*/
say (a+b) / 1 /*display normalized sum to terminal. */
say (a+b) / 1 /*display normalized sum to terminal. */
Line 4,697: Line 4,697:
===version 3, extended precision===
===version 3, extended precision===
Using the &nbsp; '''numeric digits''' &nbsp; statement allows more decimal digits to be used, the default is &nbsp; '''9'''.
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.*/
<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.*/
numeric digits 300 /*the default is nine decimal digits.*/
parse pull a b /*obtain two numbers from input stream.*/
parse pull a b /*obtain two numbers from input stream.*/
Line 4,706: Line 4,706:
===version 4, multiple numbers===
===version 4, multiple numbers===
This REXX version adds &nbsp; ''all'' &nbsp; the numbers entered &nbsp; (not just two).
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*/
<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. */
numeric digits 1000 /*just in case the user gets ka-razy. */
say 'enter some numbers to be summed:' /*display a prompt message to terminal.*/
say 'enter some numbers to be summed:' /*display a prompt message to terminal.*/
Line 4,719: Line 4,719:


===version 5, multiple numbers, tongue in cheek===
===version 5, multiple numbers, tongue in cheek===
<syntaxhighlight lang=rexx>/*REXX program obtains some numbers from the input stream (the console), shows their sum*/
<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. */
numeric digits 1000 /*just in case the user gets ka-razy. */
say 'enter some numbers to be summed:' /*display a prompt message to terminal.*/
say 'enter some numbers to be summed:' /*display a prompt message to terminal.*/
Line 4,729: Line 4,729:


=={{header|Ring}}==
=={{header|Ring}}==
<syntaxhighlight lang=ring>give Numbers
<syntaxhighlight lang="ring">give Numbers
Numbers = split(Numbers)
Numbers = split(Numbers)
sum = 0
sum = 0
Line 4,740: Line 4,740:


=={{header|Robotic}}==
=={{header|Robotic}}==
<syntaxhighlight lang=robotic>
<syntaxhighlight lang="robotic">
input string "Input A:"
input string "Input A:"
set "A" to "input"
set "A" to "input"
Line 4,753: Line 4,753:
=={{header|Rockstar}}==
=={{header|Rockstar}}==
Minimized:
Minimized:
<syntaxhighlight lang=Rockstar>
<syntaxhighlight lang="rockstar">
Listen to A number
Listen to A number
Listen to B
Listen to B
Line 4,759: Line 4,759:
</syntaxhighlight>
</syntaxhighlight>
Idiomatic:
Idiomatic:
<syntaxhighlight lang=Rockstar>
<syntaxhighlight lang="rockstar">
Listen to my voice
Listen to my voice
Listen to your thoughts
Listen to your thoughts
Line 4,766: Line 4,766:


=={{header|Ruby}}==
=={{header|Ruby}}==
<syntaxhighlight lang=ruby>puts gets.split.sum(&:to_i)</syntaxhighlight>
<syntaxhighlight lang="ruby">puts gets.split.sum(&:to_i)</syntaxhighlight>


=={{header|Run BASIC}}==
=={{header|Run BASIC}}==
<syntaxhighlight lang=runbasic>input, x$
<syntaxhighlight lang="runbasic">input, x$
print val(word$(x$,1)) + val(word$(x$,2))</syntaxhighlight>
print val(word$(x$,1)) + val(word$(x$,2))</syntaxhighlight>


=={{header|Rust}}==
=={{header|Rust}}==
<syntaxhighlight lang=rust>use std::io;
<syntaxhighlight lang="rust">use std::io;


fn main() {
fn main() {
Line 4,788: Line 4,788:
or
or


<syntaxhighlight lang=rust>use std::io;
<syntaxhighlight lang="rust">use std::io;


fn main() {
fn main() {
Line 4,801: Line 4,801:


=={{header|S-lang}}==
=={{header|S-lang}}==
<syntaxhighlight lang=C>% A+B from stdin, sans error checking
<syntaxhighlight lang="c">% A+B from stdin, sans error checking
variable input, a, b;
variable input, a, b;


Line 4,813: Line 4,813:
46</pre>
46</pre>


<syntaxhighlight lang=C>% A+B from stdin, basic validity testing
<syntaxhighlight lang="c">% A+B from stdin, basic validity testing
variable input, a, b, rc;
variable input, a, b, rc;


Line 4,826: Line 4,826:


=={{header|Scala}}==
=={{header|Scala}}==
<syntaxhighlight lang=scala>println(readLine().split(" ").map(_.toInt).sum)</syntaxhighlight>
<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:
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)
<syntaxhighlight lang="scala">val s = new java.util.Scanner(System.in)
val sum = s.nextInt() + s.nextInt()
val sum = s.nextInt() + s.nextInt()
println(sum)</syntaxhighlight>
println(sum)</syntaxhighlight>
Line 4,836: Line 4,836:
or
or


<syntaxhighlight lang=scala>println(readLine().split(" ").filter(_.length>0).map(_.toInt).sum)</syntaxhighlight>
<syntaxhighlight lang="scala">println(readLine().split(" ").filter(_.length>0).map(_.toInt).sum)</syntaxhighlight>


=={{header|Scheme}}==
=={{header|Scheme}}==
<syntaxhighlight lang=scheme>(display (+ (read) (read)))</syntaxhighlight>
<syntaxhighlight lang="scheme">(display (+ (read) (read)))</syntaxhighlight>


=={{header|Scratch}}==
=={{header|Scratch}}==
Line 4,848: Line 4,848:
=={{header|sed}}==
=={{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.
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
<syntaxhighlight lang="sed">: Loop
# All done
# All done
/^-*00* /s///
/^-*00* /s///
Line 4,876: Line 4,876:


Another method, based off of [http://unix.stackexchange.com/a/36959/11750 this StackExchange answer]:
Another method, based off of [http://unix.stackexchange.com/a/36959/11750 this StackExchange answer]:
<syntaxhighlight lang=sed>#!/bin/sed -f
<syntaxhighlight lang="sed">#!/bin/sed -f


# Add a marker in front of each digit, for tracking tens, hundreds, etc.
# Add a marker in front of each digit, for tracking tens, hundreds, etc.
Line 4,917: Line 4,917:


=={{header|Seed7}}==
=={{header|Seed7}}==
<syntaxhighlight lang=seed7>$ include "seed7_05.s7i";
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";


const proc: main is func
const proc: main is func
Line 4,932: Line 4,932:
Works with positive and negative integers, and also more than two integers.
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>
<syntaxhighlight lang="self">((stdin readLine splitOn: ' ') mapBy: [|:e| e asInteger]) sum printLine.</syntaxhighlight>


=={{header|SenseTalk}}==
=={{header|SenseTalk}}==
<syntaxhighlight lang=sensetalk>ask "Enter the first number:"
<syntaxhighlight lang="sensetalk">ask "Enter the first number:"
put it into a
put it into a


Line 4,942: Line 4,942:


put a + b</syntaxhighlight>
put a + b</syntaxhighlight>
<syntaxhighlight lang=sensetalk>put file "input.txt" into inputFile
<syntaxhighlight lang="sensetalk">put file "input.txt" into inputFile
split inputFile by space
split inputFile by space
put sum of inputFile</syntaxhighlight>
put sum of inputFile</syntaxhighlight>


=={{header|SequenceL}}==
=={{header|SequenceL}}==
<syntaxhighlight lang=sequencel>import <Utilities/Conversion.sl>;
<syntaxhighlight lang="sequencel">import <Utilities/Conversion.sl>;


main(args(2)) := stringToInt(args[1]) + stringToInt(args[2]);</syntaxhighlight>
main(args(2)) := stringToInt(args[1]) + stringToInt(args[2]);</syntaxhighlight>
Line 4,962: Line 4,962:


=={{header|SETL}}==
=={{header|SETL}}==
<syntaxhighlight lang=setl>read(A, B);
<syntaxhighlight lang="setl">read(A, B);
print(A + B);</syntaxhighlight>
print(A + B);</syntaxhighlight>


=={{header|Shiny}}==
=={{header|Shiny}}==
<syntaxhighlight lang=shiny>if (io.line 'stdin').match ~(\d+)\s+(\d+)~
<syntaxhighlight lang="shiny">if (io.line 'stdin').match ~(\d+)\s+(\d+)~
say "$a $b %(a+b)d"
say "$a $b %(a+b)d"
end</syntaxhighlight>
end</syntaxhighlight>
Line 4,972: Line 4,972:
=={{header|Sidef}}==
=={{header|Sidef}}==
Works with both positive and negative integers.
Works with both positive and negative integers.
<syntaxhighlight lang=ruby>say STDIN.readline.words.map{.to_i}.sum</syntaxhighlight>
<syntaxhighlight lang="ruby">say STDIN.readline.words.map{.to_i}.sum</syntaxhighlight>


More idiomatically:
More idiomatically:
<syntaxhighlight lang=ruby>say read(String).words»to_i»()«+»</syntaxhighlight>
<syntaxhighlight lang="ruby">say read(String).words»to_i»()«+»</syntaxhighlight>


Explicit summation:
Explicit summation:
<syntaxhighlight lang=ruby>var (a, b) = read(String).words.map{.to_i}...
<syntaxhighlight lang="ruby">var (a, b) = read(String).words.map{.to_i}...
say a+b</syntaxhighlight>
say a+b</syntaxhighlight>


=={{header|Simula}}==
=={{header|Simula}}==
<syntaxhighlight lang=simula>BEGIN
<syntaxhighlight lang="simula">BEGIN
WHILE NOT LASTITEM DO
WHILE NOT LASTITEM DO
BEGIN
BEGIN
Line 4,993: Line 4,993:
=={{header|Smalltalk}}==
=={{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.
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'!
<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
Object subclass: #ABTask
instanceVariableNames: ''
instanceVariableNames: ''
Line 5,027: Line 5,027:
{{works with|Smalltalk/X}}
{{works with|Smalltalk/X}}
{{works with|VisualWorks Smalltalk}}
{{works with|VisualWorks Smalltalk}}
<syntaxhighlight lang=smalltalk>|task|
<syntaxhighlight lang="smalltalk">|task|
task := [:inStream :outStream |
task := [:inStream :outStream |
|processLine|
|processLine|
Line 5,047: Line 5,047:
task value: ( 'dataIn.txt' asFilename readStream) value:Transcript.</syntaxhighlight>
task value: ( 'dataIn.txt' asFilename readStream) value:Transcript.</syntaxhighlight>
or:
or:
<syntaxhighlight lang=smalltalk>task value: Stdin value: Stdout.</syntaxhighlight>
<syntaxhighlight lang="smalltalk">task value: Stdin value: Stdout.</syntaxhighlight>


=={{header|smart BASIC}}==
=={{header|smart BASIC}}==
<syntaxhighlight lang=qbasic>INPUT n$
<syntaxhighlight lang="qbasic">INPUT n$
PRINT VAL(LEFT$(n$,(LEN(STR$(VAL(n$))))))+VAL(RIGHT$(n$,(LEN(n$)-LEN(STR$(VAL(n$)))-1)))</syntaxhighlight>
PRINT VAL(LEFT$(n$,(LEN(STR$(VAL(n$))))))+VAL(RIGHT$(n$,(LEN(n$)-LEN(STR$(VAL(n$)))-1)))</syntaxhighlight>


Line 5,059: 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]:
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$
<syntaxhighlight lang="qbasic">INPUT n$
SPLIT n$ TO m$,n WITH " "
SPLIT n$ TO m$,n WITH " "
PRINT m$(0),m$(1),m$(0)+m$(1)</syntaxhighlight>
PRINT m$(0),m$(1),m$(0)+m$(1)</syntaxhighlight>
Line 5,066: Line 5,066:


=={{header|SmileBASIC}}==
=={{header|SmileBASIC}}==
<syntaxhighlight lang=smilebasic>INPUT A
<syntaxhighlight lang="smilebasic">INPUT A
INPUT B
INPUT B
PRINT A+B
PRINT A+B
Line 5,073: Line 5,073:
=={{header|SNOBOL4}}==
=={{header|SNOBOL4}}==
Simple-minded solution (literally "two somethings separated by space")
Simple-minded solution (literally "two somethings separated by space")
<syntaxhighlight lang=snobol> input break(" ") . a " " rem . b
<syntaxhighlight lang="snobol"> input break(" ") . a " " rem . b
output = a + b
output = a + b
end</syntaxhighlight>
end</syntaxhighlight>
"Integer aware" solution:
"Integer aware" solution:
<syntaxhighlight lang=snobol> nums = "0123456789"
<syntaxhighlight lang="snobol"> nums = "0123456789"
input span(nums) . a break(nums) span(nums) . b
input span(nums) . a break(nums) span(nums) . b
output = a + b
output = a + b
Line 5,087: Line 5,087:
{{works with|Axiom}}
{{works with|Axiom}}
One of several possibilities:
One of several possibilities:
<syntaxhighlight lang=SPAD>(1) -> integer READ()$Lisp + integer READ()$Lisp
<syntaxhighlight lang="spad">(1) -> integer READ()$Lisp + integer READ()$Lisp
333 444
333 444


Line 5,096: Line 5,096:


=={{header|SPARK}}==
=={{header|SPARK}}==
<syntaxhighlight lang=Ada>-- By Jacob Sparre Andersen
<syntaxhighlight lang="ada">-- By Jacob Sparre Andersen
-- Validates with SPARK GPL 2010's Examiner/Simplifier
-- Validates with SPARK GPL 2010's Examiner/Simplifier


Line 5,142: Line 5,142:


=={{header|SPL}}==
=={{header|SPL}}==
<syntaxhighlight lang=spl>n = #.split(#.input("Input two numbers, separated by space:")," ")
<syntaxhighlight lang="spl">n = #.split(#.input("Input two numbers, separated by space:")," ")
#.output(n[1],"+",n[2],"=",#.val(n[1])+#.val(n[2]))</syntaxhighlight>
#.output(n[1],"+",n[2],"=",#.val(n[1])+#.val(n[2]))</syntaxhighlight>
{{in}}
{{in}}
Line 5,155: Line 5,155:


=={{header|SQL}}==
=={{header|SQL}}==
<syntaxhighlight lang=sql>select A+B</syntaxhighlight>
<syntaxhighlight lang="sql">select A+B</syntaxhighlight>
Example:
Example:
<syntaxhighlight lang=sql>select 2+3</syntaxhighlight>
<syntaxhighlight lang="sql">select 2+3</syntaxhighlight>
This should produce a result set containing the value 5.
This should produce a result set containing the value 5.


Line 5,165: Line 5,165:
{{works with|Db2 LUW}}
{{works with|Db2 LUW}}
With SQL only:
With SQL only:
<syntaxhighlight lang=sql pl>
<syntaxhighlight lang="sql pl">


CREATE OR REPLACE FUNCTION splitadd (instring VARCHAR(255))
CREATE OR REPLACE FUNCTION splitadd (instring VARCHAR(255))
Line 5,191: Line 5,191:
=={{header|SSEM}}==
=={{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>).
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
<syntaxhighlight lang="ssem">10100000000000100000000000000000 0. -5 to c acc = -A
01100000000001010000000000000000 1. Sub. 6 acc -= B
01100000000001010000000000000000 1. Sub. 6 acc -= B
11100000000001100000000000000000 2. c to 7 X = acc
11100000000001100000000000000000 2. c to 7 X = acc
Line 5,201: Line 5,201:


=={{header|Standard ML}}==
=={{header|Standard ML}}==
<syntaxhighlight lang=sml>(*
<syntaxhighlight lang="sml">(*
* val split : string -> string list
* val split : string -> string list
* splits a string at it spaces
* splits a string at it spaces
Line 5,233: Line 5,233:
{{works with|Swift|2}}
{{works with|Swift|2}}
Requires sending EOF.
Requires sending EOF.
<syntaxhighlight lang=Swift>import Foundation
<syntaxhighlight lang="swift">import Foundation


let input = NSFileHandle.fileHandleWithStandardInput()
let input = NSFileHandle.fileHandleWithStandardInput()
Line 5,250: Line 5,250:
Swift 4 and no requirement to send EOF (press enter/send newline like you normally would)
Swift 4 and no requirement to send EOF (press enter/send newline like you normally would)


<syntaxhighlight lang=Swift>
<syntaxhighlight lang="swift">
import Foundation
import Foundation


Line 5,268: Line 5,268:


=={{header|Symsyn}}==
=={{header|Symsyn}}==
<syntaxhighlight lang=Symsyn>
<syntaxhighlight lang="symsyn">


[] $s
[] $s
Line 5,279: Line 5,279:


=={{header|Tailspin}}==
=={{header|Tailspin}}==
<syntaxhighlight lang=tailspin>
<syntaxhighlight lang="tailspin">
composer nums
composer nums
[ (<WS>?) <INT> (<WS>) <INT> (<WS>?) ]
[ (<WS>?) <INT> (<WS>) <INT> (<WS>?) ]
Line 5,289: Line 5,289:


Alternatively
Alternatively
<syntaxhighlight lang=tailspin>
<syntaxhighlight lang="tailspin">
composer nums
composer nums
(<WS>?) (def a: <INT>;) (<WS>) <INT> -> $a + $ (<WS>?)
(<WS>?) (def a: <INT>;) (<WS>) <INT> -> $a + $ (<WS>?)
Line 5,299: Line 5,299:


=={{header|Tcl}}==
=={{header|Tcl}}==
<syntaxhighlight lang=tcl>scan [gets stdin] "%d %d" x y
<syntaxhighlight lang="tcl">scan [gets stdin] "%d %d" x y
puts [expr {$x + $y}]</syntaxhighlight>
puts [expr {$x + $y}]</syntaxhighlight>
Alternatively:
Alternatively:
<syntaxhighlight lang=tcl>puts [tcl::mathop::+ {*}[gets stdin]]</syntaxhighlight>
<syntaxhighlight lang="tcl">puts [tcl::mathop::+ {*}[gets stdin]]</syntaxhighlight>
To/from a file:
To/from a file:
<syntaxhighlight lang=tcl>set in [open "input.txt"]
<syntaxhighlight lang="tcl">set in [open "input.txt"]
set out [open "output.txt" w]
set out [open "output.txt" w]
scan [gets $in] "%d %d" x y
scan [gets $in] "%d %d" x y
Line 5,312: Line 5,312:


=={{header|Terraform}}==
=={{header|Terraform}}==
<syntaxhighlight lang=hcl>
<syntaxhighlight lang="hcl">
#Aamrun, August 15th, 2022
#Aamrun, August 15th, 2022


Line 5,345: Line 5,345:


=={{header|TI-83 BASIC}}==
=={{header|TI-83 BASIC}}==
<syntaxhighlight lang=ti83b>:Prompt A,B
<syntaxhighlight lang="ti83b">:Prompt A,B
:Disp A+B</syntaxhighlight>
:Disp A+B</syntaxhighlight>


Line 5,352: Line 5,352:
Note: Comments (after the semicolons) are just for explanation -- TI-83 hex assembly does not allow comments in program source code.
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
<syntaxhighlight lang="ti83b">PROGRAM:APLUSB
:AsmPrgm
:AsmPrgm
:
:
Line 5,373: Line 5,373:


=={{header|TI-89 BASIC}}==
=={{header|TI-89 BASIC}}==
<syntaxhighlight lang=ti89b>:aplusb(a,b)
<syntaxhighlight lang="ti89b">:aplusb(a,b)
:a+b</syntaxhighlight>
:a+b</syntaxhighlight>


Line 5,379: Line 5,379:
Since torque is not compatible with standard input, I will show the closest to that.
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.
It's a function that takes a single string input, that will contain the 2 numbers.
<syntaxhighlight lang=Torque>Function aPlusB(%input)
<syntaxhighlight lang="torque">Function aPlusB(%input)
{
{
return getWord(%input, 0) + getWord(%input, 1);
return getWord(%input, 0) + getWord(%input, 1);
Line 5,385: Line 5,385:


=={{header|Transd}}==
=={{header|Transd}}==
<syntaxhighlight lang=scheme>#lang transd
<syntaxhighlight lang="scheme">#lang transd


MainModule : {
MainModule : {
Line 5,394: Line 5,394:


=={{header|TSE SAL}}==
=={{header|TSE SAL}}==
<syntaxhighlight lang=TSESAL>
<syntaxhighlight lang="tsesal">
INTEGER PROC FNMathGetSumAPlusBI( INTEGER A, INTEGER B )
INTEGER PROC FNMathGetSumAPlusBI( INTEGER A, INTEGER B )
RETURN( A + B )
RETURN( A + B )
Line 5,413: Line 5,413:


=={{header|TUSCRIPT}}==
=={{header|TUSCRIPT}}==
<syntaxhighlight lang=tuscript>$$ MODE TUSCRIPT
<syntaxhighlight lang="tuscript">$$ MODE TUSCRIPT
SET input="1 2"
SET input="1 2"
SET input=SPLIT(input,": :")
SET input=SPLIT(input,": :")
Line 5,434: Line 5,434:
=={{header|UNIX Shell}}==
=={{header|UNIX Shell}}==
{{works with|Bourne Shell}}
{{works with|Bourne Shell}}
<syntaxhighlight lang=sh>#!/bin/sh
<syntaxhighlight lang="sh">#!/bin/sh
read a b || exit
read a b || exit
echo `expr "$a" + "$b"`</syntaxhighlight>
echo `expr "$a" + "$b"`</syntaxhighlight>
Line 5,443: Line 5,443:
{{works with|zsh}}
{{works with|zsh}}
Script "a+b.sh":
Script "a+b.sh":
<syntaxhighlight lang=bash>#!/bin/bash
<syntaxhighlight lang="bash">#!/bin/bash
read a b || exit
read a b || exit
echo $(( a + b ))</syntaxhighlight>
echo $(( a + b ))</syntaxhighlight>
{{Out}}
{{Out}}
<syntaxhighlight lang=bash>echo 2 3 | ksh a+b.sh
<syntaxhighlight lang="bash">echo 2 3 | ksh a+b.sh
5</syntaxhighlight>
5</syntaxhighlight>


One liner :
One liner :


<syntaxhighlight lang=bash>
<syntaxhighlight lang="bash">
a=0;b=0;read a;read b;echo "Sum of $a and $b is "$((a+b))
a=0;b=0;read a;read b;echo "Sum of $a and $b is "$((a+b))
</syntaxhighlight>
</syntaxhighlight>
Line 5,463: Line 5,463:


==={{header|C Shell}}===
==={{header|C Shell}}===
<syntaxhighlight lang=csh>set line=$<
<syntaxhighlight lang="csh">set line=$<
set input=($line)
set input=($line)
@ sum = $input[1] + $input[2]
@ sum = $input[1] + $input[2]
Line 5,469: Line 5,469:


=={{header|Ursa}}==
=={{header|Ursa}}==
<lang>#
<syntaxhighlight lang="text">#
# a + b
# a + b
#
#
Line 5,487: Line 5,487:
=={{header|Ultimate++}}==
=={{header|Ultimate++}}==


<syntaxhighlight lang=Cpp>
<syntaxhighlight lang="cpp">
#include <Core/Core.h>
#include <Core/Core.h>
#include <stdio.h>
#include <stdio.h>
Line 5,513: Line 5,513:
=={{header|Ursala}}==
=={{header|Ursala}}==
Using standard input and output streams:
Using standard input and output streams:
<syntaxhighlight lang=Ursala>#import std
<syntaxhighlight lang="ursala">#import std
#import int
#import int


Line 5,520: Line 5,520:
main = %zP+ sum:-0+ %zp*FiNCS+ sep` @L</syntaxhighlight>
main = %zP+ sum:-0+ %zp*FiNCS+ sep` @L</syntaxhighlight>
Overwriting a text file named as a command line parameter:
Overwriting a text file named as a command line parameter:
<syntaxhighlight lang=Ursala>#import std
<syntaxhighlight lang="ursala">#import std
#import int
#import int


Line 5,527: Line 5,527:
main = ~command.files.&h; <.contents:= %zP+ sum:-0+ %zp*FiNCS+ sep` @L+ ~contents></syntaxhighlight>
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>:
Creating a new file named after the input file with suffix <code>.out</code>:
<syntaxhighlight lang=Ursala>#import std
<syntaxhighlight lang="ursala">#import std
#import int
#import int


Line 5,540: Line 5,540:
=={{header|Vala}}==
=={{header|Vala}}==
Read from stdin while program running:
Read from stdin while program running:
<syntaxhighlight lang=vala>Using GLib;
<syntaxhighlight lang="vala">Using GLib;


int main (string[] args) {
int main (string[] args) {
Line 5,554: Line 5,554:
=={{header|VBA}}==
=={{header|VBA}}==
A simple version:
A simple version:
<syntaxhighlight lang=VBA>Sub AplusB()
<syntaxhighlight lang="vba">Sub AplusB()
Dim s As String, t As Variant, a As Integer, b As Integer
Dim s As String, t As Variant, a As Integer, b As Integer
s = InputBox("Enter two numbers separated by a space")
s = InputBox("Enter two numbers separated by a space")
Line 5,563: Line 5,563:
End Sub</syntaxhighlight>
End Sub</syntaxhighlight>
An other version:
An other version:
<syntaxhighlight lang=VBA>Sub Rosetta_AB()
<syntaxhighlight lang="vba">Sub Rosetta_AB()
Dim stEval As String
Dim stEval As String
stEval = InputBox("Enter two numbers, separated only by a space", "Rosetta Code", "2 2")
stEval = InputBox("Enter two numbers, separated only by a space", "Rosetta Code", "2 2")
Line 5,573: Line 5,573:
=={{header|VBScript}}==
=={{header|VBScript}}==
A simple version:
A simple version:
<syntaxhighlight lang=vb>s=InputBox("Enter two numbers separated by a blank")
<syntaxhighlight lang="vb">s=InputBox("Enter two numbers separated by a blank")
t=Split(s)
t=Split(s)
a=CInt(t(0))
a=CInt(t(0))
Line 5,580: Line 5,580:
MsgBox c </syntaxhighlight>
MsgBox c </syntaxhighlight>
An other version:
An other version:
<syntaxhighlight lang=vb>Option Explicit
<syntaxhighlight lang="vb">Option Explicit
Dim a, b
Dim a, b
Select Case WScript.Arguments.Count
Select Case WScript.Arguments.Count
Line 5,619: Line 5,619:


=={{header|Verilog}}==
=={{header|Verilog}}==
<syntaxhighlight lang=Verilog>module TEST;
<syntaxhighlight lang="verilog">module TEST;


reg signed [11:0] y;
reg signed [11:0] y;
Line 5,640: Line 5,640:


=={{header|VHDL}}==
=={{header|VHDL}}==
<syntaxhighlight lang=VHDL>LIBRARY std;
<syntaxhighlight lang="vhdl">LIBRARY std;
USE std.TEXTIO.all;
USE std.TEXTIO.all;


Line 5,665: Line 5,665:


=={{header|Visual Basic .NET}}==
=={{header|Visual Basic .NET}}==
<syntaxhighlight lang=vbnet>Module Module1
<syntaxhighlight lang="vbnet">Module Module1


Sub Main()
Sub Main()
Line 5,677: Line 5,677:


=={{header|Vlang}}==
=={{header|Vlang}}==
<syntaxhighlight lang=go>import os
<syntaxhighlight lang="go">import os


fn main() {
fn main() {
Line 5,701: Line 5,701:


=={{header|Wee Basic}}==
=={{header|Wee Basic}}==
<syntaxhighlight lang=Wee Basic>Print 1 "Enter number A:"
<syntaxhighlight lang="wee basic">Print 1 "Enter number A:"
input a
input a
Print 1 "Enter number B:"
Print 1 "Enter number B:"
Line 5,710: Line 5,710:


=={{header|Whitespace}}==
=={{header|Whitespace}}==
<syntaxhighlight lang=whitespace>
<syntaxhighlight lang="whitespace">
Line 5,726: Line 5,726:
=={{header|Wisp}}==
=={{header|Wisp}}==
{{trans|Scheme}}
{{trans|Scheme}}
<syntaxhighlight lang=scheme>
<syntaxhighlight lang="scheme">
display : + (read) (read)
display : + (read) (read)


Line 5,736: Line 5,736:


=={{header|Wren}}==
=={{header|Wren}}==
<syntaxhighlight lang=ecmascript>import "io" for Stdin, Stdout
<syntaxhighlight lang="ecmascript">import "io" for Stdin, Stdout


while (true) {
while (true) {
Line 5,761: Line 5,761:
=={{header|X86 Assembly}}==
=={{header|X86 Assembly}}==
{{works with|NASM|Linux}}
{{works with|NASM|Linux}}
<syntaxhighlight lang=asm>section .text
<syntaxhighlight lang="asm">section .text
global _start
global _start
Line 5,825: Line 5,825:
=={{header|XBS}}==
=={{header|XBS}}==
Since XBS is written in Javascript, we have to use the Javascript prompt function to get inputs.
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"));
<syntaxhighlight lang="xbs">const Amount:number = toint(window.prompt("Input an amount"));
set Stream = [];
set Stream = [];
<|(*1..Amount)=>Stream.push(window.prompt("Input a number"));
<|(*1..Amount)=>Stream.push(window.prompt("Input a number"));
Line 5,840: Line 5,840:


=={{header|xEec}}==
=={{header|xEec}}==
<syntaxhighlight lang=xEec>i# i# ma h#10 r o# p o$ p</syntaxhighlight>
<syntaxhighlight lang="xeec">i# i# ma h#10 r o# p o$ p</syntaxhighlight>


=={{header|XLISP}}==
=={{header|XLISP}}==
<syntaxhighlight lang=xlisp>(DEFUN A-PLUS-B ()
<syntaxhighlight lang="xlisp">(DEFUN A-PLUS-B ()
(DISPLAY "Enter two numbers separated by a space.")
(DISPLAY "Enter two numbers separated by a space.")
(NEWLINE)
(NEWLINE)
Line 5,858: Line 5,858:


=={{header|Xojo}}==
=={{header|Xojo}}==
<syntaxhighlight lang=xojo>var inp as string
<syntaxhighlight lang="xojo">var inp as string
var strVals() as string
var strVals() as string


Line 5,887: Line 5,887:


=={{header|XPL0}}==
=={{header|XPL0}}==
<syntaxhighlight lang=XPL0>include c:\cxpl\codes;
<syntaxhighlight lang="xpl0">include c:\cxpl\codes;
int A, B;
int A, B;
[A:= IntIn(0);
[A:= IntIn(0);
Line 5,896: Line 5,896:


=={{header|XQuery}}==
=={{header|XQuery}}==
<syntaxhighlight lang=xquery>
<syntaxhighlight lang="xquery">
(:
(:
Using the EXPath File Module, which is built into most XQuery processors
Using the EXPath File Module, which is built into most XQuery processors
Line 5,915: Line 5,915:


=={{header|Yabasic}}==
=={{header|Yabasic}}==
<syntaxhighlight lang=Yabasic>repeat
<syntaxhighlight lang="yabasic">repeat
input "Enter two numbers (betwen -1000 ... +1000): " a, b
input "Enter two numbers (betwen -1000 ... +1000): " a, b
until(valid(a) and valid(b))
until(valid(a) and valid(b))
Line 5,925: Line 5,925:


=={{header|Yorick}}==
=={{header|Yorick}}==
<syntaxhighlight lang=yorick>a = b = 0;
<syntaxhighlight lang="yorick">a = b = 0;
read, a, b;
read, a, b;
write, a + b;</syntaxhighlight>
write, a + b;</syntaxhighlight>
Line 5,932: Line 5,932:
Source -> http://ideone.com/WLtEfe
Source -> http://ideone.com/WLtEfe
Compiled -> http://ideone.com/fMt6ST
Compiled -> http://ideone.com/fMt6ST
<syntaxhighlight lang=zed>(A+B)
<syntaxhighlight lang="zed">(A+B)
comment:
comment:
#true
#true
Line 5,948: Line 5,948:


=={{header|zkl}}==
=={{header|zkl}}==
<syntaxhighlight lang=zkl>do(2){ask("A B: ").split(" ").filter().sum().println()}</syntaxhighlight>
<syntaxhighlight lang="zkl">do(2){ask("A B: ").split(" ").filter().sum().println()}</syntaxhighlight>
<pre>
<pre>
A B: 123 567
A B: 123 567
Line 5,958: Line 5,958:


=={{header|Zoea}}==
=={{header|Zoea}}==
<syntaxhighlight lang=Zoea>program: a_plus_b
<syntaxhighlight lang="zoea">program: a_plus_b
input: '7 11'
input: '7 11'
output: 18
output: 18
Line 5,967: Line 5,967:


=={{header|zonnon}}==
=={{header|zonnon}}==
<syntaxhighlight lang=zonnon>
<syntaxhighlight lang="zonnon">
module ABProblem;
module ABProblem;
var
var
Line 5,982: Line 5,982:


=={{header|ZX Spectrum Basic}}==
=={{header|ZX Spectrum Basic}}==
<syntaxhighlight lang=zxbasic>10 PRINT "Input two numbers separated by"'"space(s) "
<syntaxhighlight lang="zxbasic">10 PRINT "Input two numbers separated by"'"space(s) "
20 INPUT LINE a$
20 INPUT LINE a$
30 GO SUB 90
30 GO SUB 90
Line 5,995: Line 5,995:
Another solution
Another solution


<syntaxhighlight lang=zxbasic>10 PRINT "Input two numbers separated by"'"space(s) "
<syntaxhighlight lang="zxbasic">10 PRINT "Input two numbers separated by"'"space(s) "
20 INPUT LINE a$
20 INPUT LINE a$
30 LET ll=10e10: LET ls=0: LET i=1
30 LET ll=10e10: LET ls=0: LET i=1