A+B: Difference between revisions

4,612 bytes added ,  1 month ago
No edit summary
(23 intermediate revisions by 19 users not shown)
Line 424:
lv_output = p_first + p_second.
write : / lv_output.</syntaxhighlight>
 
=={{header|Acornsoft Lisp}}==
{{trans|Common Lisp}}
 
<pre>
Evaluate: (print (plus (read) (read)))
3 2
5
</pre>
 
=={{header|Action!}}==
Line 1,403 ⟶ 1,412:
=={{header|AWK}}==
<syntaxhighlight lang="awk">{print $1 + $2}</syntaxhighlight>
 
=={{header|BabyCobol}}==
<syntaxhighlight lang="cobol">
* NB: COBOL's ACCEPT does not work with multiple identifiers
IDENTIFICATION DIVISION.
PROGRAM-ID. PLUS.
DATA DIVISION.
01 A PICTURE IS S9999.
01 B LIKE A.
PROCEDURE DIVISION.
DISPLAY "Enter two numbers: " WITH NO ADVANCING.
ACCEPT A B.
ADD A TO B.
DISPLAY "A+B =" B.
</syntaxhighlight>
 
=={{header|BASIC}}==
Line 1,543 ⟶ 1,567:
{{works with|Chipmunk Basic}}
{{works with|GW-BASIC}}
{{works with|IS-BASIC}}
{{works with|MSX Basic}}
{{works with|Just BASIC}}
Line 1,581 ⟶ 1,606:
50 GOTO 30
60 PRINT VAL A$( TO I-1)+VAL A$(I+1 TO )</syntaxhighlight>
 
==={{header|SmallBASIC}}===
<syntaxhighlight lang="SmallBASIC">
input "Enter number A: "; a
input "Enter number B: "; b
print "A + B = "; a + b
</syntaxhighlight>
 
==={{Header|Tiny BASIC}}===
Line 1,629 ⟶ 1,661:
Loop
Return (b@)</syntaxhighlight>
 
==={{header|XBasic}}===
{{works with|Windows XBasic}}
<syntaxhighlight lang="qbasic">PROGRAM "A+B"
VERSION "0.0000"
 
DECLARE FUNCTION Entry ()
 
FUNCTION Entry ()
a$ = INLINE$("Enter integer A: ")
a = SLONG(a$)
b$ = INLINE$("Enter integer B: ")
b = SLONG(b$)
DO WHILE 1
IF ABS(a) > 1000 OR ABS(b) > 1000 THEN
PRINT "Both integers must be in the interval [-1000..1000] - try again."
PRINT
ELSE
PRINT "Their sum is"; a + b
EXIT DO
END IF
LOOP
END FUNCTION
END PROGRAM</syntaxhighlight>
 
=={{header|Batch File}}==
Line 1,777 ⟶ 1,833:
<syntaxhighlight lang="brat">numbers = g.split[0,1].map(:to_i)
p numbers[0] + numbers[1] #Prints the sum of the input</syntaxhighlight>
 
=={{header|Bruijn}}==
<syntaxhighlight lang="bruijn">
:import std/Combinator .
:import std/String .
:import std/Number .
:import std/Char C
 
main (split-by (C.eq? ' ')) → &(add ⋔ string→number)
</syntaxhighlight>
 
=={{header|Burlesque}}==
Line 2,273 ⟶ 2,339:
 
=={{header|EasyLang}}==
<syntaxhighlight lang="text">a$ = input
ia$ = 1input
repeat
while i < len a$ and substr a$ i 1 <> " "
i += 1
until i > len a$ or substr a$ i 1 = " "
.
a = number substr a$ 1 i
b = number substr a$ i -199
print a + b
</syntaxhighlight>
Line 2,536 ⟶ 2,603:
 
=={{header|Elena}}==
ELENA 56.0 :
<syntaxhighlight lang="elena">import extensions;
Line 2,555 ⟶ 2,622:
console.printLine(console.readLine()
.split()
.selectBy(mssgconst toInt<convertorOpintConvertOp>[1])
.summarize())
}</syntaxhighlight>
Line 2,653 ⟶ 2,720:
 
=={{header|Euler}}==
'''begin'''
<syntaxhighlight lang="euler">
'''out''' '''in''' + '''in'''
begin
'''end''' $
out in + in
end $
</syntaxhighlight>
 
=={{header|Euler Math Toolbox}}==
Line 2,746 ⟶ 2,811:
 
PAUSE</syntaxhighlight>
 
=={{header|Fennel}}==
{{trans|Lua}}
<syntaxhighlight lang="fennel">
(let [(a b) (io.read :*number :*number)]
(print (+ a b)))
</syntaxhighlight>
 
=={{header|Fhidwfe}}==
Line 3,234 ⟶ 3,306:
line <- getLine
print $ sum $ map cast $ words line</syntaxhighlight>
 
=={{header|Insitux}}==
<syntaxhighlight lang="insitux">(+ (to-num (prompt "Enter first number: "))
(to-num (prompt "Enter second number: ")))</syntaxhighlight>
 
=={{header|J}}==
Line 3,254 ⟶ 3,330:
 
=={{header|Java}}==
The task description is somewhat vague, if the 'input stream' is in reference to the data provided at the command line, then Java will parse these values into a <code>String</code> array, accessible via the <kbd>args</kbd> parameter of the <code>main</code> method.
<syntaxhighlight lang="java">
public static void main(String[] args) {
int A = Integer.parseInt(args[0]);
int B = Integer.parseInt(args[1]);
System.out.println(A + B);
}
</syntaxhighlight>
If the 'input stream' is the standard-in, you can use the following.<br />
The <code>Scanner</code> class can be used to "scan" the standard-in stream from left to right, returning the next value requested.
<syntaxhighlight lang="java">
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int A = scanner.nextInt();
int B = scanner.nextInt();
System.out.println(A + B);
}
</syntaxhighlight>
If the 'input stream' is referring to any abstraction, then you can use the following.<br />
In this example, the data is considered to be under a specific charset, so the integer values are parsed using UTF-8.
<syntaxhighlight lang="java">
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
</syntaxhighlight>
<syntaxhighlight lang="java">
int sum(InputStream input) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
String line = reader.readLine();
reader.close();
/* split parameter here is a regex */
String[] values = line.split(" +");
int A = Integer.parseInt(values[0]);
int B = Integer.parseInt(values[1]);
return A + B;
}
</syntaxhighlight>
<br />
An alternate implemenation
<syntaxhighlight lang="java">import java.util.Scanner;
 
Line 4,046 ⟶ 4,165:
20 INPUT "ENTER NUMBER B: ",B
30 PRINT A+B</syntaxhighlight>
 
=={{header|Nu}}==
<syntaxhighlight lang="nu">
input | parse "{a} {b}" | first | values | into int | math sum
</syntaxhighlight>
 
=={{header|Nutt}}==
<syntaxhighlight lang="Nutt">
module main
imports native.io{input.hear,output.say}
 
vals a=hear(Int),b=hear(Int)
say(a+b)
 
end
</syntaxhighlight>
 
=={{header|Nyquist}}==
Line 4,399 ⟶ 4,534:
</pre>
=== GUI version ===
{{libheader|Phix/pGUI}}
<small>(The above console version is now just a comment in the distributed file.)</small>
<!--<syntaxhighlight lang="phix">(phixonline)-->
Line 5,170 ⟶ 5,306:
 
More idiomatically:
<syntaxhighlight lang="ruby">say read(String).words»to_i»()»«+»</syntaxhighlight>
 
Explicit summation:
Line 5,839 ⟶ 5,975:
End With
end if</syntaxhighlight>
 
=={{header|Vedit macro language}}==
This version implements the task as specified in the task description.
<syntaxhighlight lang="vedit">// Input two values on single line in text format
Get_Input(10, "Enter two integers separated by a space: ")
 
// Extract two numeric values from the text
Buf_Switch(Buf_Free)
Reg_Ins(10)
BOF
#1 = Num_Eval(ADVANCE)
#2 = Num_Eval()
Buf_Quit(OK)
 
// Calculate and display the results
Num_Type(#1 + #2)</syntaxhighlight>
 
A simpler version that prompts for the two numbers separately:
<syntaxhighlight lang="vedit">#1 = Get_Num("Enter number A: ")
#2 = Get_Num("Enter number B: ")
Num_Type(#1 + #2)</syntaxhighlight>
 
=={{header|Verilog}}==
Line 5,958 ⟶ 6,115:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">import "io" for Stdin, Stdout
 
while (true) {
62

edits