I'm working on modernizing Rosetta Code's infrastructure. Starting with communications. Please accept this time-limited open invite to RC's Slack.. --Michael Mol (talk) 20:59, 30 May 2020 (UTC)

# A+B

A+B
You are encouraged to solve this task according to the task description, using any language you may know.

A+B   ─── a classic problem in programming contests,   it's given so contestants can gain familiarity with the online judging system being used.

Given two integers,   A and B.

Their sum needs to be calculated.

Input data

Two integers are written in the input stream, separated by space(s):

${\displaystyle (-1000\leq A,B\leq +1000)}$

Output data

The required output is one integer:   the sum of A and B.

Example
input   output
2 2 4
3 2 5

## 0815

|x|+%

## 11l

Translation of: Python
print(sum(input().split(‘ ’, group_delimiters' 1B).map(i -> Int(i))))

## 360 Assembly

*        A+B                       29/08/2015APLUSB   CSECT         USING  APLUSB,R12         LR     R12,R15         OPEN   (MYDATA,INPUT)LOOP     GET    MYDATA,PG          read a single record         XDECI  R4,PG              input A, in register 4         XDECI  R5,PG+12           input B, in register 5         AR     R4,R5              A+B, add register 5 to register 4, R4=R4+R         XDECO  R4,PG+24           edit A+B         XPRNT  PG,36              print A+B         B      LOOP               repeat     ATEND    CLOSE  MYDATARETURN   XR     R15,R15         BR     R14         LTORGMYDATA   DCB    LRECL=24,RECFM=FT,EODAD=ATEND,DDNAME=MYFILEPG       DS     CL24               record         DC     CL12' '         YREGS         END    APLUSB
Input:
          27          53
123         321
999           1

Output:
          27          53          80
123         321         444
999           1        1000


## 8th

gets dup . space eval n:+ . cr

## 8080 Assembly

As often happens with assembly of any kind, dealing with the I/O requirements turns the whole task into a grand tour of the language and environment, as one needs to read and parse decimal numbers, and then write back another decimal number. But simple addition is easy, even 16-bit addition. The 8080 is otherwise an 8-bit processor, but it includes a 16-bit add instruction (and only an add, not even a subtract), namely dad (for "double add"), which can take four forms:

	dad	b	; HL += BC (i.e., add BC reg pair to HL reg pair)	dad	d	; HL += DE	dad	h	; HL += HL (also known as "mul HL by two")	dad	sp	; HL += SP (actually the only way to get at SP at all)

Merely doing A+B, with 16-bit numbers so that ${\displaystyle (-1000\leq A,B\leq +1000)}$ will fit, would look like this:

	lxi	h,123	lxi	d,456	dad	d	; HL is now 579

Then, the following is what is required to wrap it all in a CP/M command line utility. Computers based on the 8080 (or processors that are backwards compatible with it, such as the 8085 and Z80) usually ran the CP/M operating system (or something that is backwards compatible with it, such as MSX-DOS or ZSDOS). This program assembles to an 128-byte binary, which fits exactly in one CP/M block.

fcb1n:	equ	5Ch+1	; "Filename" in first FCBfcb2n:	equ	6Ch+1	; "Filename" in second FCBputs:	equ	9	; CP/M call to write string to consolebdos:	equ	5	; CP/M syscall address	org	100h	lxi	d,fcb1n	; Get first "file name" (i.e, first number on cmdline)	call	parse	; Parse it	push	h	; Store the number on the stack	lxi	d,fcb2n	; Get the second one	call	parse	; Parse that one too	pop	d	; Retrieve our first number and put it in DE	dad	d 	; <-- add DE to HL, giving our answer, then fall into:	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	;;;	Routine: print the signed integer in HL. 		    ;;;	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;puthl:	mov	a,h	; Get the sign bit of the integer,	ral		; which is the top bit of the high byte	sbb	a	; A=00 if positive, FF if negative	sta	negf	; Store it as the negative flag	cnz	neghl	; And if HL was negative, make it positive	lxi	d,num	; Load pointer to end of number string	push	d	; Onto the stack	lxi	b,-10	; Divide by ten (by trial subtraction)digit:	lxi	d,-1	; DE = quotient. There is no 16-bit subtraction,dgtdiv:	dad	b	; so we just add a negative value,	inx	d	jc	dgtdiv	; while that overflows.	mvi	a,'0'+10	; The loop runs once too much so we're 10 out	add	l 	; The remainder (minus 10) is in L	xthl		; Swap HL with top of stack (i.e., the string pointer)	dcx	h	; Go back one byte	mov	m,a	; And store the digit	xthl		; Put the pointer back on the stack	xchg		; Do all of this again with the quotient	mov	a,h	; If it is zero, we're done	ora	l	jnz	digit	; But if not, there are more digits	mvi	c,puts	; Prepare to call CP/M and print the string	pop	d	; Put the string pointer from the stack in DE	lda	negf	; See if the number was supposed to be negative	inr	a	jnz	bdos	; If not, print the string we have and return	dcx	d	; But if so, we need to add a minus in front	mvi	a,'-'	stax	d	jmp	bdos	; And only then print the string	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	;;;	Routine: parse (possibly negative) 16-bit integer at [DE],  ;;;	;;;	result in HL.                                               ;;;	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;parse:	lxi	h,negf	; Zero out the negative flag	mvi	m,0	ldax	d	; Get first byte of number string	cpi	'-'	; If minus, it should be negative	jnz	prspos	; If not, parse as positive number	inr	m	; Set negative flag	inx	d	; The actual number starts one byte further onprspos:	lxi	h,0	; Set our 16-bit accumulator to zeroprsdgt:	ldax	d	; Get current digit	sui	'0'	; It's ASCII, so subtract '0'	cpi	10	; Check if it is a valid digit (<10)	jnc	prsdon	; If not, that was the last character, we're done	dad	h	; Multiply accumulator by ten	mov	b,h	; There is no MUL instruction, but 10*HL = 5*(2*HL),	mov	c,l	; = 2*HL + 8*HL. BC=2*HL	dad	h	; HL *= 2	dad	h	; HL *= 2	dad	b	; HL += BC	mov	c,a	; Then, add the digit, extended to 16 bits	mvi	b,0	; by setting the top byte to zero.	dad	b	inx	d	; Then, get the next digit	jmp	prsdgtprsdon:	lda	negf	; Check if the result was supposed to be negative	dcr	a	rnz		; If not, we're done, otherwise, fall through into...	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	;;;	Routine: negate the 16-bit integer in HL. 		    ;;;	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;neghl:	mov	a,h	; HL = -HL; i.e. HL = (~HL) + 1	cma		; Get bitwise complement of the high byte,	mov	h,a	mov	a,l	; And the low byte	cma		; We have to do it byte for byte since it is an 8-bit	mov	l,a	; processor.	inx	h	; Then add one	ret		negf:	db	0	; Space for negative flag	db	'-00000'num:	db	'' ; Space for number Output: A>add 10 10 20 A>add 10 -5 5 A>add -1000 1000 0 A>add -1234 5678 4444 ## AArch64 Assembly Works with: as version Raspberry Pi 3B version Buster 64 bits  /* ARM assembly AARCH64 Raspberry PI 3B *//* program addAetB.s */ /*******************************************//* Constantes *//*******************************************/.equ STDOUT, 1 // linux output.equ WRITE, 64 // call system Linux 64 bits .equ EXIT, 93 // call system Linux 64 bits /*******************************************//* Initialized data *//*******************************************/.dataszMessError: .asciz "Error : addAetB <number1> <number2>\n"szMessResult: .asciz "Result = "szRetourLigne: .asciz "\n"/*******************************************//* Uninitialized data *//*******************************************/.bsssZoneConv: .skip 100.text.global main main: mov fp,sp // fp <- adresse début ldr x0,[fp] // load parameters number in command line cmp x0,3 // number in command line blt 99f // no -> error ldr x0,[fp,16] // recup address of number 1 in command line bl conversionAtoD // convert string in number in registre x0 mov x1,x0 // save number1 ldr x0,[fp,24] // recup address of number 2 in command line bl conversionAtoD // convert string in number in registre x0 mov x2,x0 // save number2 add x0,x1,x2 // addition number1 number2 ldr x1,qAdrsZoneConv bl conversion10S // result decimal conversion ldr x0,qAdrszMessResult bl affichageMess // call function display ldr x0,qAdrsZoneConv bl affichageMess // call function display ldr x0, qAdrszRetourLigne bl affichageMess mov x0,0 // return code OK b 100f99: ldr x0, qAdrszMessError // adresse of message bl affichageMess // call function mov x0,1 // return code error100: // standard end programm mov x8,EXIT // request to exit program svc 0 // perform the system callqAdrszMessError: .quad szMessErrorqAdrszMessResult: .quad szMessResultqAdrsZoneConv: .quad sZoneConvqAdrszRetourLigne: .quad szRetourLigne/******************************************************************//* String display with size compute */ /******************************************************************//* x0 contains string address (string ended with zero binary) */affichageMess: stp x0,x1,[sp,-16]! // save registers stp x2,x8,[sp,-16]! // save registers mov x2,0 // size counter1: // loop start ldrb w1,[x0,x2] // load a byte cbz w1,2f // if zero -> end string add x2,x2,#1 // else increment counter b 1b // and loop2: // x2 = string size mov x1,x0 // string address mov x0,STDOUT // output Linux standard mov x8,WRITE // code call system "write" svc 0 // call systeme Linux ldp x2,x8,[sp],16 // restaur 2 registres ldp x0,x1,[sp],16 // restaur 2 registres ret // retour adresse lr x30/******************************************************************//* Decimal conversion signed */ /******************************************************************//* x0 contains the value *//* x1 contains the address of receiving area length >= 21 *//* the receiving area return a string ascii left aligned *//* et avec un zero final *//* x0 return length string whitout zero final */.equ LGZONECONV, 21conversion10S: stp x5,lr,[sp,-16]! // save registers stp x3,x4,[sp,-16]! // save registers stp x1,x2,[sp,-16]! // save registers cmp x0,0 // is negative ? bge 11f // no mov x3,'-' // yes neg x0,x0 // number inversion b 12f11: mov x3,'+' // positive number12: strb w3,[x1] mov x4,#LGZONECONV // position last digit mov x5,#10 // decimal conversion 1: // loop conversion start mov x2,x0 // copy starting number or successive quotients udiv x0,x2,x5 // division by ten msub x3,x0,x5,x2 //compute remainder add x3,x3,#48 // conversion ascii sub x4,x4,#1 // previous position strb w3,[x1,x4] // store digit cbnz x0,1b // end if quotient = zero mov x2,LGZONECONV // compute string length (21 - dernière position) sub x0,x2,x4 // no instruction rsb in 64 bits !!! // move result to area begin cmp x4,1 beq 3f // full area ? mov x2,1 // no -> begin area 2: ldrb w3,[x1,x4] // load a digit strb w3,[x1,x2] // and store at begin area add x4,x4,#1 // last position add x2,x2,#1 // et begin last postion cmp x4,LGZONECONV - 1 // end ? ble 2b // no -> loop 3: mov w3,0 strb w3,[x1,x2] // zero final add x0,x0,1 // string length must take into account the sign100: ldp x1,x2,[sp],16 // restaur 2 registers ldp x3,x4,[sp],16 // restaur 2 registers ldp x5,lr,[sp],16 // restaur 2 registers ret // return address lr x30/******************************************************************//* conversion ascii string to number */ /******************************************************************//* x0 contains string address ended by 0x0 or 0xA *//* x0 return the number */ conversionAtoD: stp x5,lr,[sp,-16]! // save registers stp x3,x4,[sp,-16]! // save registers stp x1,x2,[sp,-16]! // save registers mov x1,#0 mov x2,#10 // factor ten mov x4,x0 // save address in x4 mov x3,#0 // positive signe by default mov x0,#0 // init résult to zéro mov x5,#01: // loop to remove space at begin of string ldrb w5,[x4],1 // load in w5 string octet cbz w5,100f // string end -> end routine cmp w5,#0x0A // string end -> end routine beq 100f cmp w5,#' ' // space ? beq 1b // yes -> loop2: cmp x5,#'-' // first character is - bne 3f mov x3,#1 // negative number b 4f // previous position3: // begin loop compute digit cmp x5,#'0' // character not a digit blt 4f cmp x5,#'9' // character not a digit bgt 4f // character is a digit sub w5,w5,#48 mul x0,x2,x0 // multiply last result by factor smulh x1,x2,x0 // hight cbnz x1,99f // overflow ? add x0,x0,x5 // no -> add to result4: ldrb w5,[x4],1 // load new octet and increment to one cbz w5,5f // string end -> end routine cmp w5,#0xA // string end ? bne 3b // no -> loop5: cmp x3,#1 // test register x3 for signe cneg x0,x0,eq // if equal egal negate value cmn x0,0 // carry to zero no error b 100f99: // overflow adr x0,szMessErrDep bl affichageMess cmp x0,0 // carry to one error mov x0,#0 // if error return zéro100: ldp x1,x2,[sp],16 // restaur 2 registers ldp x3,x4,[sp],16 // restaur 2 registers ldp x5,lr,[sp],16 // restaur 2 registers ret // retur address lr x30szMessErrDep: .asciz "Number too large: overflow of 64 bits. :\n".align 4 // instruction to realign the following routines  ## ABAP report z_sum_a_b.data: lv_output type i.selection-screen begin of block input. parameters: p_first type i, p_second type i.selection-screen end of block input. at selection-screen output. %_p_first_%_app_%-text = 'First Number: '. %_p_second_%_app_%-text = 'Second Number: '. start-of-selection. lv_output = p_first + p_second. write : / lv_output. ## Action! BYTE FUNC Find(CHAR ARRAY s CHAR c BYTE POINTER err) BYTE i FOR i=1 TO s(0) DO IF s(i)=c THEN err^=0 RETURN (i) FI OD err^=1RETURN (0) INT FUNC Decode(CHAR ARRAY s BYTE start,stop BYTE POINTER err) CHAR ARRAY tmp(20),tmp2(20) INT value IF s(start)='+ THEN start==+1 FI SCopyS(tmp,s,start,stop) value=ValI(tmp) ;Check if conversion failed IF value=0 AND s(start)#'0 THEN err^=1 RETURN (0) FI ;Check if value is out of range IF value<-1000 OR value>1000 THEN err^=1 RETURN (0) FI err^=0RETURN (value) PROC Main() CHAR ARRAY s(20) BYTE pos,err,err2,value INT a,b,sum DO PrintE("Enter two integer numbers between -1000 and 1000, separated by a space or Q for quit") InputS(s) IF s(0)=1 AND (s(1)='Q OR s(1)='q) THEN EXIT FI pos=Find(s,' ,@err) IF err=0 THEN a=Decode(s,1,pos-1,@err) b=Decode(s,pos+1,s(0),@err2) err=err OR err2 FI IF err=0 THEN sum=a+b PrintF("Their sum is %I%E",sum) ELSE PrintE("Invalid input!") FI PutE(); ODRETURN Output: Enter two integer numbers between -1000 and 1000, separated by a space or Q for quit -320 547 Their sum is 227 Enter two integer numbers between -1000 and 1000, separated by a space or Q for quit 512 -1234 Invalid input! Enter two integer numbers between -1000 and 1000, separated by a space or Q for quit  ## Ada -- Standard I/O Streams with Ada.Integer_Text_Io;procedure APlusB is A, B : Integer;begin Ada.Integer_Text_Io.Get (Item => A); Ada.Integer_Text_Io.Get (Item => B); Ada.Integer_Text_Io.Put (A+B);end APlusB; Using appropriate user defined types: with Ada.Text_IO; procedure A_Plus_B is type Small_Integers is range -2_000 .. +2_000; subtype Input_Values is Small_Integers range -1_000 .. +1_000; package IO is new Ada.Text_IO.Integer_IO (Num => Small_Integers); A, B : Input_Values;begin IO.Get (A); IO.Get (B); IO.Put (A + B, Width => 4, Base => 10);end A_Plus_B; ## Agena Tested with Agena 2.9.5 Win32 scope local f := trim( io.read() ) split " "; # read a line and split into fields local a := tonumber( f[ 1 ] ); local b := tonumber( f[ 2 ] ); print( a + b )epocs ## Aime file f;list l; f_affix(f, "/dev/stdin");f_list(f, l, 0);o_integer(atoi(l[0]) + atoi(l[1]));o_newline(); ## ALGOL 60 Works with: A60 begin comment A+B; integer a,b; ininteger(0,a); ininteger(0,b); outinteger(1,a+b)end  Input: 1 2  Output:  3  ## ALGOL 68 Translation of: python Works with: ALGOL 68 version Standard - no extensions to language used Works with: ALGOL 68G version Any - tested with release 1.18.0-9h.tiny ### Console print((read int + read int)) Input: 1 2  Output:  +3  ### File open(stand in, "input.txt", stand in channel);open(stand out, "output.txt", stand out channel);print((read int + read int)) Input "input.txt": 3 4  Output "output.txt":  +7  ## ALGOL W begin integer a, b; read( a, b ); write( a + b )end. ## Amazing Hopper  #include <hbasic.h> #import lib/input.bas.lib#include include/input.h Begin Token Init Cls Locate(5,1),Print(Utf8("Ingrese dos números, separados por espacio: "))  msg=""  LocCol(45),Let( msg := ReadString(msg))  Token Sep(" ")  Print("Suma : ", Token(1),Val(Token$(msg)) Plus (Token(2),Val(Token$(msg))), Newl)End
Output:
Ingrese dos números, separados por espacio: -200 10
Suma : -190
Press any key to continue...


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

 #include <hbasic.h> #import lib/input.bas.lib#include include/input.h #define getValueOf(__X__)  Token(__X__),Val(Token$(msg)) #define-a »»(__X__) ;Move to(__X__) Begin Token Init Cls Locate(5,1),Print(Utf8$("Ingrese dos números, separados por espacio: "))  msg=""  LocCol(45),Let( msg := ReadString(msg))  Token Sep(" ")  A=0, get Value Of(1)»»(A), CLamp(-1000,1000,A)  B=0, get Value Of(2)»»(B), CLamp(-1000,1000,B)  Print("Suma : ")  Take(A, B), and Add It; then Print It with a NewlEnd
Output:
Ingrese dos números, separados por espacio: -1005 500
Suma : -500
Press any key to continue...


## Apex

  static Integer sumOfTwoNums(Integer A, Integer B) {    return A + B;} System.debug('A = 50 and B = 25: ' + sumOfTwoNums(50, 25));System.debug('A = -50 and B = 25: ' +sumOfTwoNums(-50, 25));System.debug('A = -50 and B = -25: ' +sumOfTwoNums(-50, -25));System.debug('A = 50 and B = -25: ' +sumOfTwoNums(50, -25)); '''Output'''A = 50 and B = 25: 75A = -50 and B = 25: -25A = -50 and B = -25: -75A = 50 and B = -25: 25

## APL

 ⎕+⎕

## AppleScript

Open the AppleScript Editor and save this as A+B.scpt on your Desktop

on run argv    try        return ((first item of argv) as integer) + (second item of argv) as integer    on error        return "Usage with -1000 <= a,b <= 1000: " & tab & " A+B.scpt a b"    end tryend run

To make this run in Terminal open the Terminal.app and type osascript ~/Desktop/A+B.scpt -3 78 followed by enter.

Result: 75

## Arc

 (prn (+ (read)        (read)))

## Argile

Translation of: C
Works with: Argile version 1.0.0
(: Standard input-output streams :)use std, arrayCfunc scanf "%d%d" (&val int a) (&val int b)printf "%d\n" (a + b)
(: Input file : input.txt :)(: Output file: output.txt :)use std, arraylet  in = fopen "input.txt" "r"let out = fopen "output.txt" "w"let int x, y.Cfunc fscanf in "%d%d" (&x) (&y) (:fscanf not yet defined in std.arg:)fprintf out "%d\n" (x+y)fclose infclose out

## ARM Assembly

Works with: gcc version Linux

Exploiting C standard library functions (scanf and printf). Requires arm-linux-gnueabi-gcc and qemu-arm. Compile with:

arm-linux-gnueabi-as src.s -o src.o && arm-linux-gnueabi-gcc -static src.o -o run && qemu-arm run
.text.global main.extern printf.extern scanf main:        push {lr}        ldr r0, =scanf_lit        ldr r1, =num_a        ldr r2, =num_b        bl scanf             // scanf("%d %d", &num_a, &num_b);        ldr r0, =printf_lit        ldr r1, =num_a        ldr r1, [r1]        ldr r2, =num_b        ldr r2, [r2]        add r1, r1, r2        bl printf            // printf("%d\n", num_a + num_b);        pop {pc} .datascanf_lit:      .asciz "%d %d"printf_lit:     .asciz "%d\n".align 4.bssnum_a:  .skip 4num_b:  .skip 4
Works with: gcc version Linux

Todo: -need to print numbers w/o the leading 0's. Replace them with spaces, so alignment is still the same.

Read two strings from stdin, convert to integers calculate their sum, print to stdout. A valid int is a value between -2^31 (-2147483647) and 2^31-1 (2147483647). We do not allow -2147483648 as input, but it is a valid result. E.g. -1 -2147483647. Maximum number of digits is 10. Leading 0's are counted as number length. We read signed values. We ignore leading '+'s and allow '-' for negative values. If multiple plus or minus signs precede a number, only the last one counts. minval and maxval can be used to specify any valid range, (e.g. -1000 and +1000). The range is inclusive. If 0 is specified for both ranges, range checks are not done.

Tested on RaspberryPi model B (GNU/Linux, ARMv6) Save in ab.S Build with:

as -o ab.o ab.Sld -o a.out ab.o
.data   .align   2   .code 32 .section .rodata   .align   2   .code 32 overflow_msg:  .ascii  "Invalid number. Overflow.\n"overflow_msglen = . - overflow_msgbad_input_msg:  .ascii  "Invalid input. NaN.\n"bad_input_msglen = . - bad_input_msgrange_err_msg:  .ascii  "Value out of range.\n"range_err_msglen = . - range_err_msgio_error_msg:  .ascii  "I/O error.\n"io_error_msglen = . - range_err_msg sys_exit  = 1sys_read  = 3sys_write = 4max_rd_buf = 14lf = 10m10_9 = 0x3b9aca00maxval = 1000minval = -1000 .text @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ void main()@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@   .align   2   .code 32   .type _start STT_FUNC   .global _start_start:   stmfd   sp!, {r4,r5,lr} .read_lhs:   ldr r0, =max_rd_buf   bl readint   mov r4, r0   bl printint   mov r0, r4   bl range_check .read_rhs:   ldr r0, =max_rd_buf   bl readint   mov r5, r0   bl printint   mov r0, r5   bl range_check .sum_and_print:   adds r0, r4, r5   bvs overflow   bl printint .main_exit:   mov r0, #0   bl exit   ldmfd   sp!, {r4,r5,pc} @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Read from stdin until we encounter a non-digit, or we have read bytes2rd digits.@@ Ignore leading spaces.@@ Return value to the caller converted to a signed int.@@ We read positive values, but if we read a leading '-' sign, we convert the@@ return value to two's complement.@@ The argument is max number of bytes to read from stdin.@@ int readint(int bytes2rd)@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@   .align   2   .code 32   .type readint STT_FUNC   .global readintreadint:   stmfd   sp!, {r4,r5,r6,r7,lr}   @@@@@@@@@@@@@@@   @@ r0 : #0 for stdin arg to read.   @@ r1 : ptr to current pos in local buffer.   @@ r2 : #1 to read one byte at a time.   @@ r3,r7 : tmp.   @@ r4 : number of bytes read.   @@ r5 : value of current byte.   @@ r6 : 0 while we are reading leading spaces.   @@@@@@@@@@@@@@@   sub sp, sp, r0   mov r1, sp   mov r3, #0   push {r3}        @ sp,#4: local var @isnegative. return in r1. Default value is 0/false. Positive number.   push {r0}        @ sp,#0: local var @maxbytes. const.   mov r2, #1   mov r4, #0    mov r6, #0   b .rd@ we get here if r6 is 0.@ if space, goto .rd.@ else set r6 to 1 and goto .noleading..leadchk:   mov r0, r5   bl isspace   cmp r0, #1   beq .rd .sign_chk:   mov r0, r5   push {r1}   bl issign   cmp r0, #1   streq r0, [sp,#8]   @ sp,#4 + 4 for the pushed r1.   movhi r1, #0   strhi r1, [sp,#8]   @ sp,#4 + 4 for the pushed r1.   pop {r1}   bhs .rd    mov r6, #1   b .noleading .rd:   mov r0, #0   bl read   cmp r0, #1   bne .sum_digits_eof  @ eof   mov r5, #0   ldrb r5, [r1]   cmp r6, #0   beq .leadchk .noleading:   mov r0, r5   bl isdigit   cmp r0, #1   bne .sum_digits_nan @ r5 is non-digit    add r4, r4, #1   add r1, r1, #1   @ max chars to read is received in arg[0], stored in local var at sp.   @ Only 10 can be valid, so the default of 12 leaves space for separator.   ldr r3, [sp]   cmp r4, r3   beq .sum_digits_maxrd  @ max bytes read.   b .rd     @@@@@@@@@@@@@@@   @ We have read r4 (0..arg[0](default 12)) digits when we get here. Go through them   @ and add/mul them together to calculate a number.   @ We multiply and add the digits in reverse order to simplify the multiplication.   @@@@@@@@@@@@@@@   @ r0: return value.   @ r1: local variable for read buffer.   @ r2: tmp for conversion.   @ r3,r6,r7: tmp   @ r4: number of chars we have read.   @ r5: multiplier 1,10,100.   @@@@@@@@@@@@@@@.sum_digits_nan:   mov r0, r5   bl isspace   cmp r0, #1   bne bad_input.sum_digits_maxrd:.sum_digits_eof:   mov r0, #0   mov r5, #1.count:   cmp r4, #0   beq .readint_ret   sub r4, r4, #1   sub r1, #1   ldrb r2, [r1]   sub r2, r2, #48   mov r3, r2    @ multiply r3 (char value of digit) with r5 (multiplier).   @ possible overflow.   @ MI means negative.   @ smulls multiples two signed 32 bit vals and returns a 64 bit result.   @ If we get anything in r7, the value has overflowed.   @ having r2[31] set is overflow too.   smulls r2, r7, r3, r5   cmp r7, #0   bne overflow   cmp r2, #0   bmi overflow    @@ possible overflow.   adds r0, r0, r2   bvs overflow   bmi overflow    @@ end of array check.   @@ check is needed here too, for large numbers, since 10 billion is not a valid 32 bit val.   cmp r4, #0   beq .readint_ret    @@ multiple multiplier by 10.   @@ possible overflow.   @@ too many digits is input. happens if input is more than 10 digits.   mov r3, #10   mov r6, r5   smulls r5, r7, r3, r6   cmp r7, #0   bne overflow   cmp r5, #0   bmi overflow   b .count .readint_ret:   ldr r1, [sp,#4] @ read isnegative value.   cmp r1, #0   rsbne r0, r0, #0   pop {r2}   add sp, sp, #4   add sp, sp, r2   ldmfd   sp!, {r4,r5,r6,r7,pc} @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ int isdigit(int)@@ #48..#57 ascii range for '0'..'9'.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@   .align   2   .code 32   .type isdigit STT_FUNC   .global isdigitisdigit:   stmfd   sp!, {r1,lr}   cmp r0, #48   blo .o_range   cmp r0, #57   bhi .o_range   mov r0, #1   ldmfd   sp!, {r1,pc}.o_range:   mov r0, #0   ldmfd   sp!, {r1,pc} @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ int isspace(int)@@ ascii space = 32, tab = 9, newline 10, cr = 13.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@   .align   2   .code 32   .type isspace STT_FUNC   .global isspaceisspace:   stmfd   sp!, {lr}   cmp   r0, #32   cmpne r0, #9   cmpne r0, #10   cmpne r0, #13   beq .is_space   mov r0, #0   ldmfd   sp!, {pc}.is_space:   mov r0, #1   ldmfd   sp!, {pc} @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Return value is 1 for '-' 2 for '+'.@@ int isspace(int)@@ '+' = 43 and '-' = 45.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@   .align   2   .code 32   .type issign STT_FUNC   .global issignissign:   stmfd   sp!, {lr}   cmp   r0, #43   beq .plus_sign   cmp r0, #45   beq .minus_sign   mov r0, #0   ldmfd   sp!, {pc}.plus_sign:   mov r0, #2   ldmfd   sp!, {pc}.minus_sign:   mov r0, #1   ldmfd   sp!, {pc} @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ARGS:@@ r0 : in out arg (current int value)@@ r1 : in out arg (ptr to current pos in buffer)@@ r2 : in arg (const increment. 1000_000_000, 100_000_000, 10_000_000, 1000_000, 100_000, 10_000, 1000, 100, 10, 1.)@@@@ r4 : tmp local. Outer scope must init to #10 and count down to #0.@@      Special case is INTMAX. Must init to 5 if r4 >= 1000_000_000 (0x3b9aca00 = m10_9).@@ r5: tmp@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@   .align   2   .code 32   .type get_digit STT_FUNC   .global get_digitget_digit:   stmfd  sp!, {r2,r4,r5,lr}   ldr r5, =m10_9   cmp r2, r5   movlo r4, #10   movhs r4, #5.get_digit_loop:   sub r4, #1   mul r5, r4, r2   cmp r0, r5   blo .get_digit_loop   sub r0, r5   add r4, r4, #48   strb r4, [r1], #1   ldmfd   sp!, {r2,r4,r5,pc} @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ A quick way to divide (numbers evenly divisible by 10) by 10.@@ Most ARM cpus don't have a divide instruction,@@ so this will always work.@@ A generic div function is long and not needed here.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@   .align   2.div_r2_10:   stmfd   sp!, {r0,r1,r3,lr}   mov r0, #1   mov r1, #10.find_x:   mul r3, r0, r1;   cmp r3, r2   movlo r0, r3   blo .find_x   mov r2, r0   ldmfd   sp!, {r0,r1,r3,pc} @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@   .align   2.print_neg_sign:   stmfd   sp!, {r0,r1,r2,lr}   @ 45 = '-'   mov r1, #45   push {r1}   mov r2, #1   @ r1 is ptr to our local variable (holding '-').   mov r1, sp   mov r0, #1   bl write   cmp r0, #0   blne io_error   pop {r1}   ldmfd   sp!, {r0,r1,r2,pc} @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ void printint(int val)@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@   .align   2   .code 32   .type printint STT_FUNC   .global printintprintint:   stmfd   sp!, {r4,r5,r6,lr}   mov r1, #1   ands r1, r1, r0, LSR #31   rsbne r0, r0, #0   blne .print_neg_sign   sub sp, sp, #20   mov r1, sp   mov r3, sp    ldr r2, =m10_9.getc_loop:   bl get_digit   cmp r2, #1   beq .exit_getc_loop   bl .div_r2_10   b .getc_loop.exit_getc_loop:   ldr r0, =lf   strb r0, [r1], #1    sub r2, r1, r3   mov r1, r3   mov r0, #1   bl write   cmp r0, #0   blne io_error   add sp, sp, #20   ldmfd   sp!, {r4,r5,r6,pc} @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@   .align   2range_check:   stmfd   sp!, {r4,r5,lr}   ldr r4, =minval   ldr r5, =maxval   cmp   r4, #0   cmpeq r5, #0   beq .skip_range_check   cmp r0, r4   bllt range_err   cmp r0, r5   blgt range_err.skip_range_check:   ldmfd   sp!, {r4,r5,pc} @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ void range_err()@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@   .align   2range_err:   stmfd   sp!, {lr}   ldr r2, =range_err_msglen   ldr r1, =range_err_msg   mov r0, #2   bl write   mov   r0, #-1   bl exit   ldmfd   sp!, {pc} @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ void overflow()@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@   .align   2overflow:   stmfd   sp!, {lr}   ldr r2, =overflow_msglen   ldr r1, =overflow_msg   mov r0, #2   bl write   mov   r0, #-1   bl exit   ldmfd   sp!, { pc} @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ void bad_input()@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@   .align   2bad_input:   stmfd   sp!, {lr}   ldr r2, =bad_input_msglen   ldr r1, =bad_input_msg   mov r0, #2   bl write   mov   r0, #-1   bl exit   ldmfd   sp!, {pc} @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ void io_error()@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@   .align   2io_error:   stmfd   sp!, {lr}   ldr r2, =io_error_msglen   ldr r1, =io_error_msg   mov r0, #2   bl write   mov   r0, #-1   bl exit   ldmfd   sp!, {pc} @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ void exit(int)@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@   .align   2   .code 32   .type _start STT_FUNC   .global exitexit:   stmfd   sp!, {r7, lr}   ldr r7, =sys_exit   svc #0   ldmfd   sp!, {r7, pc} @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ int write(int fd,char*buf,int len)@ Return 0 if we successfully write all bytes. Otherwise return the error code.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@   .align   2   .code 32   .type _start STT_FUNC   .global writewrite:   stmfd   sp!, {r4,r7, lr}   mov r4, r2.wr_loop:   ldr r7, =sys_write   svc #0   @ If r0 is negative, it is more than r4 with LO (unsigned <).   cmp r0, r4   sublo r4, r0   blo .wr_loop   moveq r0, #0   ldmfd   sp!, {r4,r7, pc} @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ int read(int fd,char*buf,int len)@ Return number of bytes successfully read. Ignore errors.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@   .align   2   .code 32   .type _start STT_FUNC   .global readread:   stmfd   sp!, {r7, lr}   ldr r7, =sys_read   svc #0   cmp r0, #0   movlt r0, #0   ldmfd   sp!, {r7, pc}

## Arturo

while ø [	x: map split.words input "give me 2 numbers:" 'x -> to :integer x	print add x\0 x\1]
Output:
give me 2 numbers:3 4
7
give me 2 numbers:2 5
7

  &-#$-\.-#?-[+].-#?--/  ## ATS  (* ****** ****** *)// #include"share/atspre_staload.hats"// staload UN =$UNSAFE//                                                                                                                                                     (* ****** ****** *) staload "libc/SATS/stdio.sats" (* ****** ****** *) implementmain0() = let  var A: int  var B: int  val () =  $extfcall (void, "scanf", "%d%d", [email protected], [email protected]) // end of [val] in println! ($UN.cast2int(A) + $UN.cast2int(B))end // end of [main0] (* ****** ****** *)  ## AutoHotkey This handles more than two inputs Gui, Add, Edit, vEdit ;Enter your A+B, i.e. 5+3 or 5+3+1+4+6+2Gui, Add, Button, gAdd, AddGui, Add, Edit, ReadOnly x+10 w80Gui, Showreturn Add:Gui, Submit, NoHideLoop, Parse, Edit, + ;its taking each substring separated by "+" and its storing it in A_LoopField var += A_LoopField ;here its adding it to varGuiControl, Text, Edit2, %var% ;here it displays var in the second edit controlvar := 0 ;here it makes sure var is 0 so it won't contain the value from the previous additionreturn ## AutoIt ;AutoIt Version: 3.2.10.0$num = "45  54" consolewrite ("Sum of " & $num & " is: " & sum($num))Func sum($numbers)$numm = StringSplit($numbers," ") Return$numm[1]+$numm[$numm[0]]EndFunc

### Example2

This version can handle any amount of numbers in the input:

ConsoleWrite("# A+B:" & @CRLF) Func Sum($inp) Local$num = StringSplit($inp, " "),$sum = 0	For $i = 1 To$num[0];~ 		ConsoleWrite("# num["&$i&"]:" &$num[$i] & @CRLF) ;;$sum = $sum +$num[$i] Next Return$sumEndFunc ;==>Sum $inp = "17 4"$res = Sum($inp)ConsoleWrite($inp & " --> " & $res & @CRLF)$inp = "999 42 -999"ConsoleWrite($inp & " --> " & Sum($inp) & @CRLF) ; In calculations, text counts as 0,; so the program works correctly even with this input:Local $inp = "999x y 42 -999",$res = Sum($inp)ConsoleWrite($inp & " --> " & $res & @CRLF) Output: # A+B: 17 4 --> 21 999 42 -999 --> 42 999x y 42 -999 --> 42 ## AWK {print$1 + $2} ## BASIC DEFINT A-Z tryagain:backhere = CSRLININPUT "", i$i$= LTRIM$(RTRIM$(i$))where = INSTR(i$, " ")IF where THEN a = VAL(LEFT$(i$, where - 1)) b = VAL(MID$(i$, where + 1)) c = a + b LOCATE backhere, LEN(i$) + 1    PRINT cELSE    GOTO tryagainEND IF

### OxygenBasic

 uses consoleint istring sdo  print "Enter 2 numbers separated by space "  s=input  s=ltrim(s)  exit if not s  i=instr(s," ")  exit if i<2  print val(s)+val(mid(s,i))+crloop

### Sinclair ZX81 BASIC

10 INPUT A$20 LET I=130 IF A$(I)=" " THEN GOTO 6040 LET I=I+150 GOTO 3060 PRINT VAL A$( TO I-1)+VAL A$(I+1 TO )

### Tiny BASIC

REM Rosetta Code problem: https://rosettacode.org/wiki/A+BREM by Jjuanhdez, 06/2022 10  LET C = 0    LET D = 0    PRINT "Enter an integer: "    INPUT A    IF A < 0 THEN LET C = A * -1    PRINT "Enter other integer: "    INPUT B    IF B < 0 THEN LET D = B * -1    IF C > 1000 THEN GOTO 60    IF D > 1000 THEN GOTO 6050  PRINT "Their sum is ", A + B    GOTO 7060  PRINT "Both integers must be in the range [-1000..1000] - try again."    GOTO 1070  END

### True BASIC

DO   INPUT PROMPT "Enter two integers separated by a comma: ": A, B   IF ABS(A)>1000 OR ABS(B)>1000 OR IP(A)<>A OR IP(B)<>B THEN      PRINT "Both integers must be in the interval [-1000..1000] - try again."      PRINT   ELSE      PRINT "Their sum is";A+B      EXIT DO   END IFLOOPEND

### uBasic/4tH

s = FUNC(_GetInt(1000)) + FUNC(_GetInt(1000))Print "The sum is: ";sEnd _GetInt  Param (1)  Local (1)   Do    Input "Enter a value: ", [email protected]  Until ([email protected] > [email protected] ) * ([email protected] < [email protected]+1)    Print "Wrong, must be between "; [email protected]; " and "; [email protected]; ". Try again.."  LoopReturn ([email protected])

## Batch File

Prompts version

::aplusb.cmd@echo offsetlocalset /p a="A: "set /p b="B: "set /a c=a+becho %c%endlocal

All on the commandline version

::aplusb.cmd@echo offsetlocalset a=%1set b=%2set /a c=a+becho %c%endlocal

Formula on the command line version

::aplusb.cmd@echo offsetlocalset /a c=%~1echo %c%endlocal

Example of 'Formula on the command line version'

>aplusb 123+456
579
>aplusb "1+999"
1000


Parse the input stream version (thanks to Tom Lavedas on alt.msdos.batch.nt)

::aplusb.cmd@echo offsetlocalset /p a="Input stream: "call :add %a%echo %res%endlocalgoto :eof :addset /a res=res+%1shiftif "%1" neq "" goto :add

Example of 'parse the input stream version'

>aplusb
Input stream: 1234 5678
6912
>aplusb
Input stream: 123 234 345 456 567 678 789 890
4082

## bc

Works with: GNU bc
read() + read()

## Befunge

&&[email protected]

## Bird

use Console Math define Main    $a Console.Read$b Console.Read    Console.Println Math.Add $a$bend

## BlooP

BlooP and FlooP can't actually read from stdin, but here's the procedure it would use, if it could.

 DEFINE PROCEDURE ''ADD'' [A, B]:BLOCK 0: BEGIN    OUTPUT <= A + B;BLOCK 0: END.

## bootBASIC

Both numbers are entered separately.

10 print "Number 1";20 input a30 print "Number 2";40 input b50 print a+b

## BQN

Works with: [CBQN]
#!/usr/bin/env bqn # Cut 𝕩 at occurrences of 𝕨, removing separators and empty segments# (BQNcrate phrase).Split ← (¬-˜⊢×·+»⊸>)∘≠⊔⊢ # Natural number from base-10 digits (BQNcrate phrase).Base10 ← 10⊸×⊸+˜´∘⌽ # Parse any number of space-separated numbers from string 𝕩.ParseNums ← {Base10¨ -⟜'0' ' ' Split 𝕩} # •GetLine and •_while_ are nonstandard CBQN extensions.{•Show +´ ParseNums 𝕩 ⋄ •[email protected]} •_while_ (@⊸≢) •[email protected]

## Bracmat

filter 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.

( out$( put$"Enter two integer numbers between -1000 and 1000:"    & (filter=~/#%:~<-1000:~>1000)    & get':(!filter:?a) (!filter:?b)    & !a+!b  | "Invalid input. Try again"  ));

## Brainf***

INPUT AND SUMMATIONTODO if first symbol is a minus sign print Qgo awayQ+>                                                  initialize sum to one++[                                                 loop for each input ie twice    [>>,----------[----------------------[-<+>]]<]      eat digits until space or newline    <[<]>>>    >[<                                                 until no next digit        ----------------                                    subtract ascii zero minus what we subtracted above        [->++++++++++<]                                     add ten timess that to the next digit        <[->+<]<[->+<]>>                                    shift sum and loop counter        >>    ]    <----------------                                   subtract as above from last digit as well    [-<<+>>]                                            add to sum    <-]<-                                                  subtract original one from sum OUTPUT[                                                                                                   while a number divided by ten is bigger than zero    [->+<[->+<[->+<[->+<[->+<[->+<[->+<[->+<[->+<[->--------->+<<[->>>+<<<]]]]]]]]]]>>>[-<<<+>>>]<<<]   divide by ten    >++++++++++++++++++++++++++++++++++++++++++++++++>                                                  convert remainder to ascii digit]<[.<<]                                                                                              print ascii digits

## Brat

numbers = g.split[0,1].map(:to_i)p numbers[0] + numbers[1]  #Prints the sum of the input

## Burlesque

ps++

## C

// Standard input-output streams#include <stdio.h>int main(){   int a, b;   scanf("%d%d", &a, &b);   printf("%d\n", a + b);   return 0;}
// Input file: input.txt// Output file: output.txt#include <stdio.h>int main(){   freopen("input.txt", "rt", stdin);   freopen("output.txt", "wt", stdout);   int a, b;   scanf("%d%d", &a, &b);   printf("%d\n", a + b);   return 0;}
 #include <stdio.h>#include <stdlib.h>int main(int argc, char **argv) //not sure if argv counts as input stream... certainly it is brought here via input stream.{   printf("%d\n", atoi(*(argv+1)) + atoi(*(argv+2)));   return 0;} 

## C#

using System;using System.Linq; class Program{    static void Main()    {        Console.WriteLine(Console.ReadLine().Split().Select(int.Parse).Sum());    }}

Another way (not recommended since it does not work with more than two numbers):

using System; class Program{    static void Main()    {        string input = Console.ReadLine();        int index = input.IndexOf(" ");        int num1 = int.Parse(input.Substring(0, index));        int num2 = int.Parse(input.Substring(index + 1));        int sum = num1 + num2;        Console.WriteLine(sum.ToString());    }}

## C++

// Standard input-output streams#include <iostream>using namespace std;int main(){   int a, b;   cin >> a >> b;   cout << a + b << endl;}
// Input file: input.txt// Output file: output.txt#include <fstream>using namespace std;int main(){   ifstream in("input.txt");   ofstream out("output.txt");   int a, b;   in >> a >> b;   out << a + b << endl;   return 0;}

## Ceylon

shared void run() {     print("please enter two numbers for me to add");    value input = process.readLine();    if (exists input) {        value tokens = input.split().map(Integer.parse);        if (tokens.any((element) => element is ParseException)) {            print("numbers only, please");            return;        }        value numbers = tokens.narrow<Integer>();        if (numbers.size != 2) {            print("two numbers, please");        }        else if (!numbers.every((Integer element) => -1k <= element <= 1k)) {            print("only numbers between -1000 and 1000, please");        }        else if (exists a = numbers.first, exists b = numbers.last) {            print(a + b);        }        else {            print("something went wrong");        }    }}

## Clojure

(println (+ (Integer/parseInt (read-line)) (Integer/parseInt (read-line))))34=>7
(eval (read-string (str "(+ " (read-line) " )") ))3 36

Translation of Common Lisp version:

(println (+ (read) (read)))3 47

Safely and without reader tricks:

(let [ints (map #(Integer/parseInt %) (clojure.string/split (read-line) #"\s") )]   (println (reduce + ints)))3 4=>7

or same as above, but without "let":

(println (reduce + (map #(Integer/parseInt %) (clojure.string/split (read-line) #"\s") ))) 3 4=>7

## COBOL

       IDENTIFICATION DIVISION.       PROGRAM-ID. A-Plus-B.        DATA DIVISION.       WORKING-STORAGE SECTION.       01  A       PIC S9(5).       01  B       PIC S9(5).        01  A-B-Sum PIC S9(5).        PROCEDURE DIVISION.           ACCEPT A           ACCEPT B            ADD A TO B GIVING A-B-Sum            DISPLAY A-B-Sum            GOBACK           .

A second version.

         IDENTIFICATION DIVISION.       PROGRAM-ID. A-Plus-B.       AUTHOR.  Bill Gunshannon.       INSTALLATION.  Home.       DATE-WRITTEN.  25 December 2021.      ************************************************************      ** Program Abstract:      **   A re-worked version that more closely matches the      **     desired format. Both numbers are taken in on one      **     line separated by spaces. Sum is formated to remove      **     leading zeros and/or spaces.      ************************************************************         DATA DIVISION.       WORKING-STORAGE SECTION.       01  Input-Data   PIC X(16).       01  A            PIC S9(5).       01  B            PIC S9(5).        01  A-B-Sum PIC -----9.        PROCEDURE DIVISION.           DISPLAY "Input pairs of numbers separated by spaces."           DISPLAY "Enter q to exit."           PERFORM WITH TEST BEFORE                   UNTIL Input-Data = "q" or Input-Data = "Q"           ACCEPT Input-Data                IF Input-Data NOT = "q" and Input-Data NOT = "Q"                  UNSTRING Input-Data DELIMITED BY SPACES                        INTO A B                  ADD A TO B GIVING A-B-Sum                   DISPLAY "Sum = " FUNCTION TRIM(A-B-Sum)                END-IF           END-PERFORM.            STOP RUN.  

## CoffeeScript

Translation of: JavaScript
<html><script type="text/javascript" src="http://jashkenas.github.com/coffee-script/extras/coffee-script.js"></script><script type="text/coffeescript">a = window.prompt 'enter A number', ''b = window.prompt 'enter B number', ''document.getElementById('input').innerHTML = a + ' ' + bsum = parseInt(a) + parseInt(b)document.getElementById('output').innerHTML = sum</script><body><div id='input'></div><div id='output'></div></body></html>
Works with: Node.js
 { stdin } = processsum = ( a, b ) -> a + b display = ( messages... ) -> console.log messages... parse = ( input ) ->    parseInt x for x in ( x.trim() for x in input.split ' ' ) when x?.length check = ( numbers... ) ->    return no for x in numbers when isNaN x    return no for x in numbers when not ( -1000 < x < 1000 )    yes prompt = ->    display 'Please enter two integers between -1000 and 1000, separated by a space:'    stdin.once 'data', ( data ) ->        [ a, b ] = parse data        if check a, b            display "#{ a } + #{ b } = #{ sum a, b }"        else            display "Invalid input: #{ a }, #{ b }"        do prompt        return # Resume input and set the incoming encoding.stdin.resume()stdin.setEncoding 'utf8' # Start the main loop.do prompt 

## Common Lisp

(write (+ (read) (read)))

## Component Pascal

BlackBox Component Builder

 MODULE AB;IMPORT StdLog, DevCommanders,TextMappers; PROCEDURE DoAB(x,y: INTEGER);BEGIN        StdLog.Int(x);StdLog.Int(y);StdLog.Int(x + y);StdLog.Ln;END DoAB; PROCEDURE Go*;VAR                params: DevCommanders.Par;                s: TextMappers.Scanner;                p : ARRAY 2 OF INTEGER;                current: INTEGER;BEGIN        current := 0;        params := DevCommanders.par;        s.ConnectTo(params.text);        s.SetPos(params.beg);        s.Scan;        WHILE(~s.rider.eot) DO                IF (s.type = TextMappers.int) THEN                        p[current] := s.int; INC(current);                END;                s.Scan;        END;        IF current = 2 THEN DoAB(p[0],p[1]) END;END Go;END AB. 

Execute: AB.Go 12 23 ~

Output:
12 23 35


## Computer/zero Assembly

        STP      ; wait for inputa:           0b:           0        LDA  a        ADD  b        STP

## Crystal

puts gets.not_nil!.split.map(&.to_i).sum

The not_nil! call on gets is needed because gets might return nil and the compiler forces us to deal with it. In the case of nil a runtime exception will be thrown.

To handle the nil case we could do:

if line = gets  puts line.split.map(&.to_i).sumelse  puts "No input"end

## D

### From Console

import std.stdio, std.conv, std.string; void main() {    string[] r;    try        r = readln().split();    catch (StdioException e)        r = ["10", "20"];     writeln(to!int(r[0]) + to!int(r[1]));}
Output:
30

### From File

void main() {    import std.stdio, std.file;     immutable ab = "sum_input.txt".slurp!(int, int)("%d %d")[0];    "sum_output.txt".File("w").writeln(ab[0] + ab[1]);}

## Diego

begin_instuct(A + B);    ask_human()_msg(Please enter two integers between -1000 and 1000, separated by a space:)_split( )_var(A, B);    with_var(A, B)_trim()_parse({integer})_test([A]<=-1000)_test([B]>=1000)        : with_human[]_msg(Invalid input: [A], [B]);           exec_instruct[];    ;    add_var(sum)_calc([A]+[B]);    with_human[]_msg([A] [B]  [sum]);end_instruct[]; exec_instruct(A + B)_me();

## DMS

number a = GetNumber( "Please input 'a'", a, a )    // prompts for 'a'number b = GetNumber( "Please input 'b'", b, b )    // prompts for 'b'Result( a + b + "\n" )

## Dragon

 select "graphic"select "types" a = int(prompt("Enter A number"))b = int(prompt("Enter B number")) showln a + b 

## DWScript

Ghetto GUI version

var a := StrToInt(InputBox('A+B', 'Enter 1st number', '0'));var b := StrToInt(InputBox('A+B', 'Enter 2nd number', '0'));ShowMessage('Sum is '+IntToStr(a+b));

## Déjà Vu

Translation of: Python

### Console

0for k in split !prompt "" " ":	+ to-num k!print

## Euler Math Toolbox

 >s=lineinput("Two numbers seperated by a blank"); Two numbers seperated by a blank? >4 5>vs=strtokens(s) 4 5>vs[1]()+vs[2]() 9 

## Euphoria

include get.e function snd(sequence s)    return s[2]end function integer a,b a = snd(get(0))b = snd(get(0)) printf(1," %d\n",a+b)

## Excel

Take any 3 columns of any row or rows. Let's say A1,B1 and C1 are taken. In C1 type in :

 =A1+B1 

The value of C1 will change as the values of A1 and B1 are changed

1	2	3 

## F#

open System let SumOf(str : string) =    str.Split() |> Array.sumBy(int) [<EntryPoint>]let main argv =     Console.WriteLine(SumOf(Console.ReadLine()))    0

## Factor

USING: math.parser splitting ;: a+b ( -- )    readln " " split1    [ string>number ] [email protected] +    number>string print ;
( scratchpad ) a+b
2 2
4


$txr -p '(+ (read) (read))' 1.2 2.3 3.5 ## TypeScript function add(a: number, b: number) { return a+b; }  ## UNIX Shell Works with: Bourne Shell #!/bin/shread a b || exitecho expr "$a" + "$b" Works with: bash Works with: ksh93 Works with: pdksh Works with: zsh Script "a+b.sh": #!/bin/bashread a b || exitecho$(( a + b ))
Output:
echo 2 3 | ksh a+b.sh5

One liner :

## Ursa

## a + b# # read a string containing the two intsdecl string inputset input (in string console) # determine the sumdecl int sumset sum (int (+ sum (int (split input " ")<0>)))set sum (int (+ sum (int (split input " ")<1>))) # output the sumout sum endl console

## Ultimate++

 #include <Core/Core.h>#include <stdio.h>#include <iostream> using namespace Upp; CONSOLE_APP_MAIN{ 	int a, b;	a = 2, b = 3;	printf("%d + %d = %d\n",a,b,(a + b));	std::cout << std::endl << a << " + " << b << " = " << (a + b) << std::endl; 	const Vector<String>& cmdline = CommandLine();	for(int i = 0; i < cmdline.GetCount(); i++) {	}}

## Ursala

Using standard input and output streams:

#import std#import int #executable& main = %zP+ sum:-0+ %zp*FiNCS+ sep @L

Overwriting a text file named as a command line parameter:

#import std#import int #executable -[parameterized]- main = ~command.files.&h; <.contents:= %zP+ sum:-0+ %zp*FiNCS+ sep @L+ ~contents>

Creating a new file named after the input file with suffix .out:

## VHDL

LIBRARY std;USE std.TEXTIO.all;  entity test isend entity test;  architecture beh of test isbegin  process    variable line_in, line_out : line;    variable a,b : integer;  begin    readline(INPUT, line_in);    read(line_in, a);    read(line_in, b);     write(line_out, a+b);    writeline(OUTPUT, line_out);    wait; -- needed to stop the execution  end process;end architecture beh;

## Visual Basic .NET

Module Module1   Sub Main()    Dim s() As String = Nothing     s = Console.ReadLine().Split(" "c)    Console.WriteLine(CInt(s(0)) + CInt(s(1)))  End Sub End Module

## XLISP

(DEFUN A-PLUS-B ()    (DISPLAY "Enter two numbers separated by a space.")    (NEWLINE)    (DISPLAY "> ")    (DEFINE A (READ))    (DEFINE B (READ))    (+ A B))
Output:
(A-PLUS-B)
Enter two numbers separated by a space.
> 2 2

4

## Xojo

var inp as stringvar strVals() as string print("Enter two numbers separated by a space:") do  inp = input    strVals = inp.split(" ")   var a, b as integer   a = strVals(0).toInteger  b = strVals(1).toInteger   if a < -1000 or b > 1000 then    print("The first number should be greater than or equal to -1000 and the second number should be less " + _    "than or equal to 1000. Please re-enter:")    continue  end   var result as integer = a + b  print(a.toString + " + " + b.toString + " = " + result.toString)  exitloop

## XPL0

include c:\cxpl\codes;int A, B;[A:= IntIn(0); B:= IntIn(0); IntOut(0, A+B); CrLf(0);]

 (:   Using the EXPath File Module, which is built into most XQuery processors   by default and thus does not need to get imported. Some processors bind the  namespace automatically, others require explicit declaration.:) xquery version "3.1"; declare namespace file = 'http://expath.org/ns/file'; let $in := 'input.txt'let$out      := 'output.txt'let $numbers := tokenize(file:read-text($in))let $result := xs:numeric($numbers[1]) + xs:numeric($numbers[2])return file:write-text($out, xs:string($result))  ## Yabasic repeat input "Enter two numbers (betwen -1000 ... +1000): " a, buntil(valid(a) and valid(b))print "\nThe sum of ", a, " and ", b, " is: ", a + b sub valid(x) return x >= -1000 and x <= 1000end sub ## Yorick a = b = 0;read, a, b;write, a + b; ## ZED Source -> http://ideone.com/WLtEfe Compiled -> http://ideone.com/fMt6ST (A+B)comment:#true(+) (read) (read) (+) one twocomment:#true(003) "+" one two (read)comment:#true(001) "read" ## zkl do(2){ask("A B: ").split(" ").filter().sum().println()} A B: 123 567 690 A B: -4 6 2  This actually works for any number of integers ## Zoea program: a_plus_b input: '7 11' output: 18  ## Zoea Visual ## zonnon  module ABProblem;var a,b: integer;begin read(a,b); writeln(a+b)end ABProblem.  1 2 3  ## ZX Spectrum Basic 10 PRINT "Input two numbers separated by"'"space(s) "20 INPUT LINE a$30 GO SUB 9040 FOR i=1 TO LEN a$50 IF a$(i)=" " THEN LET a=VAL a$( TO i): LET b=VAL a$(i TO ): PRINT a;" + ";b;" = ";a+b: GO TO 7060 NEXT i70 STOP 80 REM LTrim operation90 IF a$(1)=" " THEN LET a$=a$(2 TO ): GO TO 90100 RETURN Another solution 10 PRINT "Input two numbers separated by"'"space(s) "20 INPUT LINE a$30 LET ll=10e10: LET ls=0: LET i=140 IF a$(i)=" " THEN LET ls=i: GO TO 6050 LET ll=i60 IF ls>ll THEN GO TO 8070 LET i=i+1: GO TO 4080 LET a=VAL a$( TO i): LET b=VAL a\$(i TO )90 PRINT a;" + ";b;" = ";a+b
Input two numbers separated by
space(s)
3.14     2^3
3.14 + 8 = 11.14