Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -1,5 +1,6 @@
|
|||
{{basic data operation}} [[Category:Simple]]
|
||||
Get two integers from the user, and then output the sum, difference, product, integer quotient and remainder of those numbers. Don't include error handling.
|
||||
Get two integers from the user, and then output the sum, difference, product, integer quotient and remainder of those numbers.
|
||||
Don't include error handling.
|
||||
For quotient, indicate how it rounds (e.g. towards 0, towards negative infinity, etc.).
|
||||
For remainder, indicate whether its sign matches the sign of the first operand or of the second operand, if they are different.
|
||||
|
||||
|
|
|
|||
39
Task/Arithmetic-Integer/360-Assembly/arithmetic-integer.360
Normal file
39
Task/Arithmetic-Integer/360-Assembly/arithmetic-integer.360
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
* Arithmetic/Integer 04/09/2015
|
||||
ARITHINT CSECT
|
||||
USING ARITHINT,R12
|
||||
LR R12,R15
|
||||
ADD L R1,A
|
||||
A R1,B r1=a+b
|
||||
XDECO R1,BUF
|
||||
MVI BUF,C'+'
|
||||
XPRNT BUF,12
|
||||
SUB L R1,A
|
||||
S R1,B r1=a-b
|
||||
XDECO R1,BUF
|
||||
MVI BUF,C'-'
|
||||
XPRNT BUF,12
|
||||
MUL L R1,A
|
||||
M R0,B r0r1=a*b
|
||||
XDECO R1,BUF so r1 has the lower part
|
||||
MVI BUF,C'*'
|
||||
XPRNT BUF,12
|
||||
DIV L R0,A
|
||||
SRDA R0,32 to shift the sign
|
||||
D R0,B r1=a/b and r0 has the remainder
|
||||
XDECO R1,BUF so r1 has quotient
|
||||
MVI BUF,C'/'
|
||||
XPRNT BUF,12
|
||||
MOD L R0,A
|
||||
SRDA R0,32 to shift the sign
|
||||
D R0,B r1=a/b and r0 has the remainder
|
||||
XDECO R0,BUF so r0 has the remainder
|
||||
MVI BUF,C'R'
|
||||
XPRNT BUF,12
|
||||
RETURN XR R15,R15
|
||||
BR R14
|
||||
CNOP 0,4
|
||||
A DC F'53'
|
||||
B DC F'11'
|
||||
BUF DC CL12' '
|
||||
YREGS
|
||||
END ARITHINT
|
||||
|
|
@ -12,7 +12,9 @@ begin
|
|||
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) & ", remainder " & Integer'Image(A mod 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;
|
||||
|
|
|
|||
8
Task/Arithmetic-Integer/DCL/arithmetic-integer.dcl
Normal file
8
Task/Arithmetic-Integer/DCL/arithmetic-integer.dcl
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
$ inquire a "Enter first number"
|
||||
$ a = f$integer( a )
|
||||
$ inquire b "Enter second number"
|
||||
$ b = f$integer( b )
|
||||
$ write sys$output "a + b = ", a + b
|
||||
$ write sys$output "a - b = ", a - b
|
||||
$ write sys$output "a * b = ", a * b
|
||||
$ write sys$output "a / b = ", a / b ! truncates down
|
||||
|
|
@ -6,12 +6,12 @@
|
|||
|
||||
#symbol program =
|
||||
[
|
||||
#var(type:int) a := consoleEx readLine:(Integer new) int.
|
||||
#var(type:int)b := consoleEx readLine:(Integer new) int.
|
||||
#var a := console readLine:(Integer new).
|
||||
#var b := console readLine:(Integer new).
|
||||
|
||||
consoleEx writeLine:a:" + ": b:" = ":(a + b).
|
||||
consoleEx writeLine:a:" - ": b:" = ":(a - b).
|
||||
consoleEx writeLine:a:" * ": b:" = ":(a * b).
|
||||
consoleEx writeLine:a:" / ": b:" = ":(a / b). // truncates towards 0
|
||||
consoleEx writeLine:a:" %% ":b:" = ":(a mod:b). // matches sign of first operand
|
||||
console writeLine:a:" + ": b:" = ":(a + b).
|
||||
console writeLine:a:" - ": b:" = ":(a - b).
|
||||
console writeLine:a:" * ": b:" = ":(a * b).
|
||||
console writeLine:a:" / ": b:" = ":(a / b). // truncates towards 0
|
||||
console writeLine:a:" % ":b:" = ":(a mod:b). // matches sign of first operand
|
||||
].
|
||||
|
|
|
|||
15
Task/Arithmetic-Integer/Elixir/arithmetic-integer.elixir
Normal file
15
Task/Arithmetic-Integer/Elixir/arithmetic-integer.elixir
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# Function to remove line breaks and convert string to int
|
||||
get_int = fn msg -> IO.gets(msg) |> String.strip |> String.to_integer end
|
||||
|
||||
# Get user input
|
||||
a = get_int.("Enter your first integer: ")
|
||||
b = get_int.("Enter your second integer: ")
|
||||
|
||||
IO.puts "Elixir Integer Arithmetic:\n"
|
||||
IO.puts "Sum: #{a + b}"
|
||||
IO.puts "Difference: #{a - b}"
|
||||
IO.puts "Product: #{a * b}"
|
||||
IO.puts "True Division: #{a / b}" # Float
|
||||
IO.puts "Division: #{div(a,b)}" # Truncated Towards 0
|
||||
IO.puts "Remainder: #{rem(a,b)}" # Sign from first digit
|
||||
IO.puts "Exponent: #{:math.pow(a,b)}" # Float, using Erlang's :math
|
||||
17
Task/Arithmetic-Integer/Factor/arithmetic-integer.factor
Normal file
17
Task/Arithmetic-Integer/Factor/arithmetic-integer.factor
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
USING: combinators io kernel math math.functions math.order
|
||||
math.parser prettyprint ;
|
||||
|
||||
"a=" "b=" [ write readln string>number ] bi@
|
||||
{
|
||||
[ + "sum: " write . ]
|
||||
[ - "difference: " write . ]
|
||||
[ * "product: " write . ]
|
||||
[ / "quotient: " write . ]
|
||||
[ /i "integer quotient: " write . ]
|
||||
[ rem "remainder: " write . ]
|
||||
[ mod "modulo: " write . ]
|
||||
[ max "maximum: " write . ]
|
||||
[ min "minimum: " write . ]
|
||||
[ gcd "gcd: " write . drop ]
|
||||
[ lcm "lcm: " write . ]
|
||||
} 2cleave
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
/* NetRexx */
|
||||
|
||||
options replace format comments java crossref savelog symbols binary
|
||||
options replace format comments java crossref symbols binary
|
||||
|
||||
say "enter 2 integer values separated by blanks"
|
||||
parse ask a b
|
||||
|
|
|
|||
|
|
@ -1,26 +1,24 @@
|
|||
/*REXX pgm gets 2 integers from the C.L. or via prompt, shows some opers*/
|
||||
numeric digits 20 /*all numbers are rounded at ··· */
|
||||
/*··· the 20th significant digit.*/
|
||||
parse arg x y . /*maybe the integers are on C.L.?*/
|
||||
if y=='' then do /*nope, then prompt user for 'em.*/
|
||||
say "─────Enter two integer values (separated by blanks):"
|
||||
parse pull x y .
|
||||
end
|
||||
do 2 /*show A with B, then B with A.*/
|
||||
say /*show blank line for eyeballing.*/
|
||||
/*REXX pgm gets 2 integers from the C,L. or via prompt; shows some operations.*/
|
||||
numeric digits 20 /*#s are round at 20th significant dig.*/
|
||||
parse arg x y . /*maybe the integers are on the C.L. */
|
||||
|
||||
call show 'addition' , "+", x+y
|
||||
call show 'subtraction' , "-", x-y
|
||||
call show 'multiplication', "*", x*y
|
||||
call show 'int division' , "%", x%y, ' [rounds down]'
|
||||
call show 'real division' , "/", x/y
|
||||
call show 'div remainder' , "//", x//y, ' [sign from 1st operand]'
|
||||
call show 'power' , "**", x**y
|
||||
do while \datatype(x,'W') | \datatype(y,'W') /*both X and Y must be ints.*/
|
||||
say "─────Enter two integer values (separated by blanks):"
|
||||
parse pull x y . /*accept two items from command line. */
|
||||
end /*while ··· */
|
||||
/* [↓] perform this DO loop twice. */
|
||||
do j=1 for 2 /*show A oper B, then B oper A.*/
|
||||
call show 'addition' , "+", x+y
|
||||
call show 'subtraction' , "-", x-y
|
||||
call show 'multiplication' , "*", x*y
|
||||
call show 'int division' , "%", x%y, ' [rounds down]'
|
||||
call show 'real division' , "/", x/y
|
||||
call show 'division remainder', "//", x//y, ' [sign from 1st operand]'
|
||||
call show 'power' , "**", x**y
|
||||
|
||||
parse value x y with y x /*swap the two values & do again.*/
|
||||
end /*2*/
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────SHOW subroutine─────────────────────*/
|
||||
show: parse arg what,oper,value,comment
|
||||
say right(what,25)' ' x center(oper,4) y ' ───► ' value comment
|
||||
return
|
||||
parse value x y with y x /*swap the two values and perform again*/
|
||||
if j==1 then say copies('═', 79) /*display a fence after the 1st round. */
|
||||
end /*j*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*────────────────────────────────────────────────────────────────────────────*/
|
||||
show: parse arg c,o,#,?; say right(c,25)' ' x center(o,4) y ' ───► ' # ?; return
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
use std::io;
|
||||
use std::env;
|
||||
|
||||
fn main() {
|
||||
#![allow(unstable)] // Currently required whilst Rust 1.0 is finalised
|
||||
let a: i32 = from_str(io::stdin().read_line().unwrap().trim().as_slice()).unwrap();
|
||||
let b: i32 = from_str(io::stdin().read_line().unwrap().trim().as_slice()).unwrap();
|
||||
let args: Vec<_> = env::args().collect();
|
||||
let a = args[1].parse::<i32>().unwrap();
|
||||
let b = args[2].parse::<i32>().unwrap();
|
||||
|
||||
let sum = a + b;
|
||||
println!("a + b = {0}" , sum);
|
||||
println!("a - b = {0}" , a - b);
|
||||
println!("a * b = {0}" , a * b);
|
||||
println!("quotient of a / b = {0}" , a / b); // truncates towards 0
|
||||
println!("remainder of a / b = {0}" , a % b); // same sign as first operand
|
||||
println!("sum: {}", a + b);
|
||||
println!("difference: {}", a - b);
|
||||
println!("product: {}", a * b);
|
||||
println!("integer quotient: {}", a / b); // truncates towards zero
|
||||
println!("remainder: {}", a % b); // same sign as first operand
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue