Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -1,14 +0,0 @@
begin
integer a, b;
write( "Enter 2 integers> " );
read( a, b );
write( "a + b: ", a + b ); % addition %
write( "a - b: ", a - b ); % subtraction %
write( "a * b: ", a * b ); % multiplication %
write( "a / b: ", a div b ); % integer division %
write( "a mod b: ", a rem b ); % modulo %
% the ** operator returns a real result even with integer operands %
% ( the right-hand operand must always be an integer, the left-hand %
% operand can be integer, real or complex ) %
write( "a ^ b: ", round( a ** b ) )
end.

View file

@ -0,0 +1,20 @@
with Ada.Text_Io;
with Ada.Integer_Text_IO;
procedure Integer_Arithmetic is
use Ada.Text_IO;
use Ada.Integer_Text_Io;
A, B : Integer;
begin
Get(A);
Get(B);
Put_Line("a+b = " & Integer'Image(A + B));
Put_Line("a-b = " & Integer'Image(A - B));
Put_Line("a*b = " & Integer'Image(A * B));
Put_Line("a/b = " & Integer'Image(A / B));
Put_Line("a mod b = " & Integer'Image(A mod B)); -- Sign matches B
Put_Line("remainder of a/b = " & Integer'Image(A rem B)); -- Sign matches A
Put_Line("a**b = " & Integer'Image(A ** B));
end Integer_Arithmetic;

View file

@ -5,10 +5,7 @@ function divmod(int a, int b) returns [int, int] {
}
function pow(int n, int e) returns int {
if e < 1 { return 1; }
int prod = 1;
foreach int i in 1...e { prod *= n; }
return prod;
return <int> (<float> n).pow(<float> e);
}
public function main() returns error? {
@ -17,8 +14,8 @@ public function main() returns error? {
io:println("sum: ", a + b);
io:println("difference: ", a - b);
io:println("product: ", a * b);
io:println("integer quotient: ", a / b); // rounds towards zero
io:println("remainder: ", a % b); // sign matches sign of first operand
io:println("integer quotient: ", a / b);
io:println("remainder: ", a % b);
io:println("exponentiation: ", pow(a, b));
io:println("divmod ", divmod(a, b));
io:println("divmod: ", divmod(a, b));
}

View file

@ -0,0 +1,44 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. Int-Arithmetic.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A PIC S9(10).
01 B PIC S9(10).
01 Result PIC S9(10).
PROCEDURE DIVISION.
DISPLAY "First number: " WITH NO ADVANCING
ACCEPT A
DISPLAY "Second number: " WITH NO ADVANCING
ACCEPT B
* *> Note: The various ADD/SUBTRACT/etc. statements can be
* *> replaced with COMPUTE statements, which allow those
* *> operations to be defined similarly to other languages,
* *> e.g. COMPUTE Result = A + B
ADD A TO B GIVING Result
DISPLAY "A + B = " Result
SUBTRACT B FROM A GIVING Result
DISPLAY "A - B = " Result
MULTIPLY A BY B GIVING Result
DISPLAY "A * B = " Result
* *> Division here truncates towards zero. DIVIDE can take a
* *> ROUNDED clause, which will round the result to the nearest
* *> integer.
DIVIDE A BY B GIVING Result
DISPLAY "A / B = " Result
COMPUTE Result = A ^ B
DISPLAY "A ^ B = " Result
* *> Matches sign of first argument.
DISPLAY "A % B = " FUNCTION REM(A, B)
GOBACK
.

View file

@ -0,0 +1,13 @@
include get.e
integer a,b
a = floor(prompt_number("a = ",{}))
b = floor(prompt_number("b = ",{}))
printf(1,"a + b = %d\n", a+b)
printf(1,"a - b = %d\n", a-b)
printf(1,"a * b = %d\n", a*b)
printf(1,"a / b = %g\n", a/b) -- does not truncate
printf(1,"remainder(a,b) = %d\n", remainder(a,b)) -- same sign as first operand
printf(1,"power(a,b) = %g\n", power(a,b))

View file

@ -0,0 +1,20 @@
import gleam/format
import gleam/int
import gleam/result
import input
pub fn main() -> Result(Nil, Nil) {
// Using these libs:
// https://hexdocs.pm/input/index.html
// https://hexdocs.pm/format/gleam/format.html
use str1 <- result.try(input.input(prompt: "> "))
use str2 <- result.try(input.input(prompt: "> "))
use a <- result.try(int.parse(str1))
use b <- result.try(int.parse(str2))
format.printf("Sum = ~w~n", [a + b])
format.printf("Difference = ~w~n", [a - b])
format.printf("Product = ~w~n", [a * b])
format.printf("Quotient = ~w~n", [a / b])
format.printf("Remainder = ~w~n", [a % b])
Ok(Nil)
}

View file

@ -0,0 +1,16 @@
class Main {
static public function main():Void {
var input_a = Sys.stdin().readLine();
var input_b = Sys.stdin().readLine();
var a = Std.parseInt(input_a);
var b = Std.parseInt(input_b);
trace(a + b);
trace(a - b);
trace(a * b);
trace(Std.int(a / b));
trace(a % b);
trace(Math.pow(a, b));
}
}

View file

@ -0,0 +1,17 @@
HAI 1.3
I HAS A X
I HAS A Y
VISIBLE "Enter an integer: "!
GIMMEH X
VISIBLE "Enter another integer: "!
GIMMEH Y
VISIBLE "sum: " SUM OF X AN Y
VISIBLE "difference: " DIFF OF X AN Y
VISIBLE "product: " PRODUKT OF X AN Y
VISIBLE "quotient: " QUOSHUNT OF X AN Y BTW rounds toward zero
VISIBLE "remainder: " MOD OF X AN Y BTW same sign as first argument
KTHXBYE

View file

@ -1,12 +0,0 @@
MODULE Arithmetic;
IMPORT In, Out;
VAR
x,y:INTEGER;
BEGIN
Out.String("Give two numbers: ");In.Int(x);In.Int(y);
Out.String("x + y >");Out.Int(x + y,6);Out.Ln;
Out.String("x - y >");Out.Int(x - y,6);Out.Ln;
Out.String("x * y >");Out.Int(x * y,6);Out.Ln;
Out.String("x / y >");Out.Int(x DIV y,6);Out.Ln;
Out.String("x MOD y >");Out.Int(x MOD y,6);Out.Ln;
END Arithmetic.

View file

@ -1,13 +1,13 @@
local function divmod(a, b) return { a // b, a % b } end
io.write("Input the first integer : ")
local a = io.read("n")
local a = tonumber(io.read())
io.write("Input the second integer: ")
local b = io.read("n")
print($"sum: {a + b}")
print($"difference {a - b}")
print($"product {a * b}")
print($"quotient {a // b}")
print($"remainder {a % b}")
print($"exponentation {math.tointeger(a ^ b)}")
print($"divmod {divmod(a, b):concat(", ")}")
local b = tonumber(io.read())
print($"sum: {a + b}")
print($"difference {a - b}")
print($"product {a * b}")
print($"quotient {a // b}")
print($"remainder {a % b}")
print($"exponentiation {a ** b}")
print($"divmod {divmod(a, b):concat(", ")}")

View file

@ -0,0 +1,9 @@
$a = [int] (Read-Host First Number)
$b = [int] (Read-Host Second Number)
Write-Host "Sum: $($a + $b)"
Write-Host "Difference: $($a - $b)"
Write-Host "Product: $($a * $b)"
Write-Host "Quotient: $($a / $b)"
Write-Host "Quotient, round to even: $([Math]::Round($a / $b))"
Write-Host "Remainder, sign follows first: $($a % $b)"

View file

@ -0,0 +1 @@
[Math]::Pow($a, $b)

View file

@ -0,0 +1,14 @@
let a = int_of_string(Sys.argv[2])
let b = int_of_string(Sys.argv[3])
let sum = a + b
let difference = a - b
let product = a * b
let division = a / b
let remainder = mod(a, b)
Js.log("a + b = " ++ string_of_int(sum))
Js.log("a - b = " ++ string_of_int(difference))
Js.log("a * b = " ++ string_of_int(product))
Js.log("a / b = " ++ string_of_int(division))
Js.log("a % b = " ++ string_of_int(remainder))

View file

@ -0,0 +1,51 @@
Rebol [
Title: "Integer"
URL: http://rosettacode.org/wiki/Arithmetic/Integer
]
x: to-integer ask "Please type in an integer, and press [enter]: "
y: to-integer ask "Please enter another integer: "
print ""
print ["Sum:" x + y]
print ["Difference:" x - y]
print ["Product:" x * y]
print ["Integer quotient (coercion) :" to-integer x / y]
print ["Integer quotient (away from zero) :" round x / y]
print ["Integer quotient (halves round towards even digits) :" round/even x / y]
print ["Integer quotient (halves round towards zero) :" round/half-down x / y]
print ["Integer quotient (round in negative direction) :" round/floor x / y]
print ["Integer quotient (round in positive direction) :" round/ceiling x / y]
print ["Integer quotient (halves round in positive direction):" round/half-ceiling x / y]
print ["Remainder:" r: x // y]
; REBOL evaluates infix expressions from left to right. There are no
; precedence rules -- whatever is first gets evaluated. Therefore when
; performing this comparison, I put parens around the first term
; ("sign? a") of the expression so that the value of /a/ isn't
; compared to the sign of /b/. To make up for it, notice that I don't
; have to use a specific return keyword. The final value in the
; function is returned automatically.
match?: func [a b][(sign? a) = sign? b]
result: copy []
if match? r x [append result "first"]
if match? r y [append result "second"]
; You can evaluate arbitrary expressions in the middle of a print, so
; I use a "switch" to provide a more readable result based on the
; length of the /results/ list.
print [
"Remainder sign matches:"
switch length? result [
0 ["neither"]
1 [result/1]
2 ["both"]
]
]
print ["Exponentiation:" x ** y]

View file

@ -0,0 +1,9 @@
a: input "Enter an integer: " |to-integer
b: input "Enter another integer: " |to-integer
print "sum: " ++ a + b
print "difference: " ++ a - b
print "product: " ++ a * b
print "quotient: " ++ a // b ; rounds toward zero
print "remainder: " ++ a % b ; same sign as the first arg
print "power: " ++ a .math/pow b

View file

@ -0,0 +1,22 @@
readIO Enter an integer x:
x = i
readIO Enter an integer y:
y = i
print x + y =
z = x + y
printInt z
print x - y =
z = x - y
printInt z
print x * y =
z = x * y
printInt z
print x / y =
z = x / y // round toward zero
printInt z
print x % y =
z = x % y // result retains sign of the first argument
printInt z
print x ^ y =
z = x ^ y
printInt z

View file

@ -0,0 +1,8 @@
&sc
⊜□≠@ .
⇌pars
&p/-.&p/+.
&p/(⌊%).&p/*.
&p/◿.
&p/ⁿ.
pop

View file

@ -0,0 +1,17 @@
option explicit
dim a, b
wscript.stdout.write "A? "
a = wscript.stdin.readline
wscript.stdout.write "B? "
b = wscript.stdin.readline
a = int( a )
b = int( b )
wscript.echo "a + b=", a + b
wscript.echo "a - b=", a - b
wscript.echo "a * b=", a * b
wscript.echo "a / b=", a / b
wscript.echo "a \ b=", a \ b
wscript.echo "a mod b=", a mod b
wscript.echo "a ^ b=", a ^ b

View file

@ -0,0 +1,14 @@
option explicit
dim a, b
wscript.stdout.write "A? "
a = wscript.stdin.readline
wscript.stdout.write "B? "
b = wscript.stdin.readline
a = int( a )
b = int( b )
dim op
for each op in split("+ - * / \ mod ^", " ")
wscript.echo "a",op,"b=",eval( "a " & op & " b")
next