Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1,3 +1,6 @@
{{basic data operation}}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.
{{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.
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.
Also include the exponentiation operator if one exists.

View file

@ -1,4 +1,5 @@
---
category:
- Arithmetic operations
- Arithmetic
note: Basic language learning

View file

@ -1,4 +1,4 @@
Function( a, b )
procedure Test( a, b )
? "a+b", a + b
? "a-b", a - b
? "a*b", a * b
@ -8,4 +8,4 @@ Function( a, b )
? "a%b", a % b
// Exponentiation is also a base arithmetic operation
? "a**b", a ** b
Return Nil
return

View file

@ -1,16 +1,17 @@
#define system.
#define system'math.
#define extensions.
// --- Program ---
#symbol program =
[
#var a := consoleEx readLine:(Integer new).
#var b := consoleEx readLine:(Integer new).
#var(type:int) a := consoleEx readLine:(Integer new) int.
#var(type:int)b := consoleEx readLine:(Integer new) int.
consoleEx << a << " + " << b << " = " << a + b << "%n".
consoleEx << a << " - " << b << " = " << a - b << "%n".
consoleEx << a << " * " << b << " = " << a * b << "%n".
consoleEx << a << " / " << b << " = " << a / b << "%n". // truncates towards 0
consoleEx << a << " %% " << b << " = " << (a~mathOp mod:b) << "%n". // matches sign of first operand
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
].

View file

@ -0,0 +1 @@
=$A1+$B1

View file

@ -0,0 +1 @@
=$A1-$B1

View file

@ -0,0 +1 @@
=$A1*$B1

View file

@ -0,0 +1 @@
=QUOTIENT($A1,$B1)

View file

@ -0,0 +1 @@
=MOD($A1,$B1)

View file

@ -0,0 +1 @@
=$A1^$B1

View file

@ -0,0 +1,5 @@
function arithmetic (a = int(readline()), b = int(readline()))
for op in [+,-,*,div,rem]
println("a $op b = $(op(a,b))")
end
end

View file

@ -0,0 +1,9 @@
print_expression_and_result(M, N, Operator) :-
Expression =.. [Operator, M, N],
Result is Expression,
format('~w ~8|is ~d~n', [Expression, Result]).
arithmetic_integer :-
read(M),
read(N),
maplist( print_expression_and_result(M, N), [+,-,*,//,rem,^] ).

View file

@ -0,0 +1,10 @@
?- arithmetic_integer.
|: 5.
|: 7.
5+7 is 12
5-7 is -2
5*7 is 35
5//7 is 0
5 rem 7 is 5
5^7 is 78125
true.

View file

@ -1,10 +1,11 @@
puts 'Enter x and y'
x=gets.to_i # to check errors, use x=Integer(gets)
y=gets.to_i
x = gets.to_i # to check errors, use x=Integer(gets)
y = gets.to_i
puts "Sum: #{x+y}",
"Difference: #{x-y}",
"Product: #{x*y}",
"Quotient: #{x/y}", # truncates towards negative infinity
"Remainder: #{x%y}", # same sign as second operand
"Quotient: #{x/y}", # truncates towards negative infinity
"Quotient: #{x.fdiv(y)}", # float
"Remainder: #{x%y}", # same sign as second operand
"Exponentiation: #{x**y}"

View file

@ -0,0 +1,14 @@
use std::io;
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 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
}

View file

@ -1,9 +1,9 @@
val a = Console.readInt
val b = Console.readInt
val sum = a + b;//integer addition is discouraged in print statements due to confusion with String concatenation
println("a + b = " + sum);
println("a - b = " + (a - b));
println("a * b = " + (a * b));
println("quotient of a / b = " + (a / b)); // truncates towards 0
println("remainder of a / b = " + (a % b)); // same sign as first operand
val sum = a + b //integer addition is discouraged in print statements due to confusion with String concatenation
println("a + b = " + sum)
println("a - b = " + (a - b))
println("a * b = " + (a * b))
println("quotient of a / b = " + (a / b)) // truncates towards 0
println("remainder of a / b = " + (a % b)) // same sign as first operand

View file

@ -0,0 +1,10 @@
let a = float2nr(input("Number 1: ") + 0)
let b = float2nr(input("Number 2: ") + 0)
echo "\nSum: " . (a + b)
echo "Difference: " . (a - b)
echo "Product: " . (a * b)
" The result of an integer division is truncated
echo "Quotient: " . (a / b)
" The sign of the result of the remainder operation matches the sign of
" the first operand
echo "Remainder: " . (a % b)