Arithmetic/Integer: Difference between revisions

m
imported>Arakov
 
(7 intermediate revisions by 6 users not shown)
Line 333:
.include "../includeARM64.inc"
</syntaxhighlight>
{{Output : Out}}
<PRE>
pi@debian-buster-64:~/asm64/rosetta/asm3 $ arith64 101 25
Line 978:
PRINT "MOD(", a%, ", ", b%, ") is ", MOD(a%, b%), ", same sign as first operand"
PRINT "POW(", a%, ", ", b%, ") is ", INT(POW(a%, b%))</syntaxhighlight>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
<syntaxhighlight lang="qbasic">10 input "Enter two integers separated by a comma: ";a,b
20 print " Sum: ";a+b
30 print "Difference: ";a-b
40 print " Product: ";a*b
50 print " Quontent: ";int(a/b)
60 print " Remainder: ";a mod b
70 print " Power: ";a^b</syntaxhighlight>
 
==={{header|Commodore BASIC}}===
Line 988 ⟶ 998:
70 PRINT "REMAINDER OR MODULO:";A%;"%";B%;"=";A%-INT(A%/B%)*B%
80 PRINT "POWER:";A%;"^";B%;"=";A%^B%</syntaxhighlight>
 
==={{header|GW-BASIC}}===
{{works with|PC-BASIC|any}}
{{works with|BASICA}}
<syntaxhighlight lang="qbasic">10 INPUT "Enter two integers separated by a comma: ";A, B
20 PRINT " Sum:"; A + B
30 PRINT "Difference:"; A - B
40 PRINT " Product:"; A * B
50 PRINT " Quontent:"; A \ B
60 PRINT " Remainder:"; A MOD B
70 PRINT " Power:"; A ^ B</syntaxhighlight>
 
==={{header|Minimal BASIC}}===
<syntaxhighlight lang="qbasic">10 PRINT "ENTER A INTEGER"
20 INPUT A
30 PRINT "ENTER ANOTHER INTEGER"
40 INPUT B
50 PRINT " SUM: "; A + B
60 PRINT "DIFFERENCE: "; A - B
70 PRINT " PRODUCT: "; A * B
80 PRINT " QUONTENT: "; INT(A / B)
90 PRINT " REMAINDER: "; A - INT(A / B ) * B
100 PRINT " POWER:"; A ^ B
110 END</syntaxhighlight>
 
==={{header|MSX Basic}}===
{{works with|MSX BASIC|any}}
<syntaxhighlight lang="qbasic">10 INPUT "Enter two integers separated by a comma: ";A, B
20 PRINT " Sum:"; A + B
30 PRINT "Difference:"; A - B
40 PRINT " Product:"; A * B
50 PRINT " Quontent:"; A \ B
60 PRINT " Remainder:"; A MOD B
70 PRINT " Power:"; A ^ B</syntaxhighlight>
 
==={{header|Quite BASIC}}===
<syntaxhighlight lang="qbasic">10 INPUT "enter a integer"; A
20 INPUT "enter another integer"; B
30 PRINT " Sum: "; A + B
40 PRINT "Difference: "; A - B
50 PRINT " Product: "; A * B
60 PRINT " Quontent: "; INT(A / B)
70 PRINT " Remainder: "; A - INT(A / B ) * B</syntaxhighlight>
 
==={{Header|Tiny BASIC}}===
Line 1,028 ⟶ 1,081:
PRINT "POW(";a;", ";b;") is ";INT(a^b)
GET KEY done
END</syntaxhighlight>
END
</syntaxhighlight>
 
==={{header|QBasic}}===
Line 1,043 ⟶ 1,095:
 
Remainder sign matches: first operand
 
==={{header|XBasic}}===
{{works with|Windows XBasic}}
<syntaxhighlight lang="qbasic">PROGRAM "IntegerArithmetic"
VERSION "0.0000"
 
DECLARE FUNCTION Entry ()
 
FUNCTION Entry ()
a$ = INLINE$("Enter integer A: ")
a = SLONG(a$)
b$ = INLINE$("Enter integer B: ")
b = SLONG(b$)
PRINT
PRINT " Sum:"; a + b
PRINT "Difference:"; a - b
PRINT " Product:"; a * b
PRINT " Quontent:"; a / b
PRINT " Remainder:"; a MOD b
PRINT " Power:"; a ** b
END FUNCTION
END PROGRAM</syntaxhighlight>
 
=={{header|BASIC256}}==
Line 1,501 ⟶ 1,575:
}</syntaxhighlight>
Division and modulus are defined as in C99.
 
=={{header|Dart}}==
<syntaxhighlight lang="dart">import 'dart:io';
import 'dart:math' show pow;
 
void main() {
print('enter a integer: ');
int a = int.parse(stdin.readLineSync());
print('enter another integer: ');
int b = int.parse(stdin.readLineSync());
 
print('a + b = ${a + b}');
print('a - b = ${a - b}');
print('a * b = ${a * b}');
print('a / b = ${a ~/ b}');
print('a % b = ${a % b}');
print('a ^ b = ${pow(a, b)}');
 
//Integer division uses the '~/' operator
}</syntaxhighlight>
 
=={{header|dc}}==
Line 1,696 ⟶ 1,790:
 
=={{header|Elena}}==
ELENA 46.x :
<syntaxhighlight lang="elena">import system'math;
import extensions;
Line 1,709 ⟶ 1,803:
console.printLine(a," * ",b," = ",a * b);
console.printLine(a," / ",b," = ",a / b); // truncates towards 0
console.printLine(a," % ",b," = ",a.mod:(b)); // matches sign of first operand
console.printLine(a," ^ ",b," = ",a ^ b);
}</syntaxhighlight>
Line 2,991 ⟶ 3,085:
math_pow(#a,#b) // 1296
math_pow(#b,#a) // 4096</syntaxhighlight>
 
=={{header|LDPL}}==
<syntaxhighlight lang="ldpl">data:
x is number
y is number
result is number
 
procedure:
display "Enter x: "
accept x
display "Enter y: "
accept y
add x and y in result
display "x + y = " result lf
subtract y from x in result
display "x - y = " result lf
multiply x by y in result
display "x * y = " result lf
divide x by y in result # There is no integer division but
floor result # floor rounds toward negative infinity
display "x / y = " result lf
modulo x by y in result
display "x % y = " result lf # Returns the sign of the 2nd argument
raise x to y in result
display "x ^ y = " result lf</syntaxhighlight>
{{out}}
<pre>
Enter x: 13
Enter y: 4
x + y = 17
x - y = 9
x * y = 52
x / y = 3
x % y = 1
x ^ y = 28561
</pre>
 
=={{header|LFE}}==
Line 3,789 ⟶ 3,919:
Pop $0
FunctionEnd</syntaxhighlight>
 
=={{header|Nu}}==
Division rounds towards -infinity. Modulus will match the sign of the first number.
 
<syntaxhighlight lang="nu">
input | parse "{a} {b}" | first | values | into int | do {|a b|
{
Sum: ($a + $b)
Difference: ($a - $b)
Product: ($a * $b)
Quotient: ($a // $b)
Remainder: ($a mod $b)
Exponent: ($a ** $b)
}
} $in.0 $in.1
</syntaxhighlight>
{{out}}
<pre>
-1 2
╭────────────┬────╮
│ Sum │ 1 │
│ Difference │ -3 │
│ Product │ -2 │
│ Quotient │ -1 │
│ Remainder │ -1 │
│ Exponent │ 1 │
╰────────────┴────╯
</pre>
 
=={{header|Nutt}}==
Line 5,084 ⟶ 5,242:
 
] applyTo: {Integer readFrom: (query: 'Enter a: '). Integer readFrom: (query: 'Enter b: ')}.</syntaxhighlight>
 
=={{header|SmallBASIC}}==
<syntaxhighlight lang="SmallBASIC">
input "Enter first number : "; A
input "Enter second number: "; B
 
print "Sum : "; A + B
print "Difference: "; A - B
print "Product : "; A * B
print "Quotient : "; A \ B ' Integer quotient rounds towards smaller number
print "Remainder : "; A % B ' sign of remainder is given by sign of first operand
print "Power : "; A ^ B
</syntaxhighlight>
 
=={{header|Smalltalk}}==
Line 5,768 ⟶ 5,939:
 
The sign of the remainder operator '%' matches the sign of the first operand.
<syntaxhighlight lang="ecmascriptwren">import "io" for Stdin, Stdout
System.write("first number: ")
Stdout.flush()
Anonymous user