A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
3
Task/Integer-comparison/0DESCRIPTION
Normal file
3
Task/Integer-comparison/0DESCRIPTION
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{{basic data operation}}Get two integers from the user, and then output if the first one is less, equal or greater than the other. Test the condition ''for each case separately'', so that ''all three comparison operators are used'' in the code.
|
||||
|
||||
See also:[[String comparison]]
|
||||
4
Task/Integer-comparison/1META.yaml
Normal file
4
Task/Integer-comparison/1META.yaml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
category:
|
||||
- Arithmetic operations
|
||||
note: Basic Data Operations
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
Compare PHA ;push Accumulator onto stack
|
||||
JSR GetUserInput ;routine not implemented
|
||||
;integers to compare now in memory locations A and B
|
||||
LDA A
|
||||
CMP B ;sets flags as if a subtraction (a - b) had been carried out
|
||||
BCC A_less_than_B ;branch if carry clear
|
||||
BEQ A_equals_B ;branch if equal
|
||||
;else A greater than B
|
||||
JSR DisplayAGreaterThanB;routine not implemented
|
||||
JMP Done
|
||||
A_less_than_B: JSR DisplayALessThanB ;routine not implemented
|
||||
JMP Done
|
||||
A_equals_B: JSR DisplayAEqualsB ;routine not implemented
|
||||
Done: PLA ;restore Accumulator from stack
|
||||
RTS ;return from subroutine
|
||||
21
Task/Integer-comparison/ALGOL-68/integer-comparison.alg
Normal file
21
Task/Integer-comparison/ALGOL-68/integer-comparison.alg
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
main: (
|
||||
INT a, b;
|
||||
read((a, space, b, new line));
|
||||
|
||||
IF a <= b OR a LE b # OR a ≤ b # THEN
|
||||
print((a," is less or equal to ", b, new line))
|
||||
FI;
|
||||
IF a < b OR a LT b THEN
|
||||
print((a," is less than ", b, new line))
|
||||
ELIF a = b OR a EQ b THEN
|
||||
print((a," is equal to ", b, new line))
|
||||
ELIF a > b OR a GT b THEN
|
||||
print((a," is greater than ", b, new line))
|
||||
FI;
|
||||
IF a /= b OR a NE b # OR a ≠ b # THEN
|
||||
print((a," is not equal to ", b, new line))
|
||||
FI;
|
||||
IF a >= b OR a GE b # OR a ≥ b # THEN
|
||||
print((a," is greater or equal to ", b, new line))
|
||||
FI
|
||||
)
|
||||
5
Task/Integer-comparison/AWK/integer-comparison-1.awk
Normal file
5
Task/Integer-comparison/AWK/integer-comparison-1.awk
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
/[0-9]* [0-9]*/{
|
||||
if ($1 == $2) print $1, "is equal to", $2
|
||||
if ($1 < $2) print $1, "is less than", $2
|
||||
if ($1 > $2) print $1, "is greater than", $2
|
||||
}
|
||||
2
Task/Integer-comparison/AWK/integer-comparison-2.awk
Normal file
2
Task/Integer-comparison/AWK/integer-comparison-2.awk
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
# This code contains a bug
|
||||
IF (n=3) PRINT "n is equal to 3" # The incorrectly used equals sign will set n to a value of 3
|
||||
24
Task/Integer-comparison/Ada/integer-comparison.ada
Normal file
24
Task/Integer-comparison/Ada/integer-comparison.ada
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Ada.Integer_Text_IO; use Ada.Integer_Text_Io;
|
||||
|
||||
procedure Compare_Ints is
|
||||
A, B : Integer;
|
||||
begin
|
||||
Get(Item => A);
|
||||
Get(Item => B);
|
||||
|
||||
-- Test for equality
|
||||
if A = B then
|
||||
Put_Line("A equals B");
|
||||
end if;
|
||||
|
||||
-- Test For Less Than
|
||||
if A < B then
|
||||
Put_Line("A is less than B");
|
||||
end if;
|
||||
|
||||
-- Test For Greater Than
|
||||
if A > B then
|
||||
Put_Line("A is greater than B");
|
||||
end if;
|
||||
end Compare_Ints;
|
||||
27
Task/Integer-comparison/Aime/integer-comparison.aime
Normal file
27
Task/Integer-comparison/Aime/integer-comparison.aime
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
void
|
||||
output(integer a, integer b, text condition)
|
||||
{
|
||||
o_integer(a);
|
||||
o_text(condition);
|
||||
o_integer(b);
|
||||
o_byte('\n');
|
||||
}
|
||||
|
||||
|
||||
integer
|
||||
main(void)
|
||||
{
|
||||
if (a < b) {
|
||||
output(a, b, " is less then ");
|
||||
}
|
||||
|
||||
if (a == b) {
|
||||
output(a, b, " is equal to ");
|
||||
}
|
||||
|
||||
if (a > b) {
|
||||
output(a, b, " is greater than ");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
set n1 to text returned of (display dialog "Enter the first number:" default answer "") as integer
|
||||
set n2 to text returned of (display dialog "Enter the second number:" default answer "") as integer
|
||||
set msg to {n1}
|
||||
if n1 < n2 then
|
||||
set end of msg to " is less than "
|
||||
else if n1 = n2 then
|
||||
set end of msg to " is equal to "
|
||||
else if n1 > n2 then
|
||||
set end of msg to " is greater than "
|
||||
end if
|
||||
set end of msg to n2
|
||||
return msg as string
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
set n1 to text returned of (display dialog "Enter the first number:" default answer "") as integer
|
||||
set n2 to text returned of (display dialog "Enter the second number:" default answer "") as integer
|
||||
if n1 < n2 then return "" & n1 & " is less than " & n2
|
||||
if n1 = n2 then return "" & n1 & " is equal to " & n2
|
||||
if n1 > n2 then return "" & n1 & " is greater than " & n2
|
||||
20
Task/Integer-comparison/AutoHotkey/integer-comparison.ahk
Normal file
20
Task/Integer-comparison/AutoHotkey/integer-comparison.ahk
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
Gui, Add, Edit
|
||||
Gui, Add, UpDown, vVar1
|
||||
Gui, Add, Edit
|
||||
Gui, Add, UpDown, vVar2
|
||||
Gui, Add, Button, Default, Submit
|
||||
Gui, Show
|
||||
Return
|
||||
|
||||
ButtonSubmit:
|
||||
Gui, Submit, NoHide
|
||||
If (Var1 = Var2)
|
||||
MsgBox, % Var1 "=" Var2
|
||||
Else If (Var1 < Var2)
|
||||
MsgBox, % Var1 "<" Var2
|
||||
Else If (Var1 > Var2)
|
||||
MsgBox, % Var1 ">" Var2
|
||||
Return
|
||||
|
||||
GuiClose:
|
||||
ExitApp
|
||||
7
Task/Integer-comparison/BASIC/integer-comparison.bas
Normal file
7
Task/Integer-comparison/BASIC/integer-comparison.bas
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
CLS
|
||||
INPUT "a, b"; a, b 'remember to type the comma when you give the numbers
|
||||
PRINT "a is ";
|
||||
IF a < b THEN PRINT "less than ";
|
||||
IF a = b THEN PRINT "equal to ";
|
||||
IF a > b THEN PRINT "greater than ";
|
||||
PRINT "b"
|
||||
6
Task/Integer-comparison/BBC-BASIC/integer-comparison.bbc
Normal file
6
Task/Integer-comparison/BBC-BASIC/integer-comparison.bbc
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
INPUT "Enter two numbers separated by a comma: " a, b
|
||||
CASE TRUE OF
|
||||
WHEN a < b: PRINT ;a " is less than "; b
|
||||
WHEN a = b: PRINT ;a " is equal to "; b
|
||||
WHEN a > b: PRINT ;a " is greater than "; b
|
||||
ENDCASE
|
||||
4
Task/Integer-comparison/Befunge/integer-comparison.bf
Normal file
4
Task/Integer-comparison/Befunge/integer-comparison.bf
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
v v ">" $<
|
||||
>&&"=A",,\:."=B ",,,\: .55+,-:0`|
|
||||
v "<" _v#<
|
||||
@,+55,," B",,,"A " < "=" <
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
get$:?A
|
||||
& get$:?B
|
||||
& (!A:!B&out$"A equals B"|)
|
||||
& (!A:<!B&out$"A is less than B"|)
|
||||
& (!A:>!B&out$"A is greater than B"|);
|
||||
6
Task/Integer-comparison/Burlesque/integer-comparison.blq
Normal file
6
Task/Integer-comparison/Burlesque/integer-comparison.blq
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
blsq ) "5 6"ps^pcm+.{"The first one is less than the second one""They are both equal""The second one is less than the first one"}\/!!sh
|
||||
The first one is less than the second one
|
||||
blsq ) "6 6"ps^pcm+.{"The first one is less than the second one""They are both equal""The second one is less than the first one"}\/!!sh
|
||||
They are both equal
|
||||
blsq ) "6 5"ps^pcm+.{"The first one is less than the second one""They are both equal""The second one is less than the first one"}\/!!sh
|
||||
The second one is less than the first one
|
||||
20
Task/Integer-comparison/C++/integer-comparison.cpp
Normal file
20
Task/Integer-comparison/C++/integer-comparison.cpp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int a, b;
|
||||
cin >> a >> b;
|
||||
|
||||
// test for less-than
|
||||
if (a < b)
|
||||
cout << a << " is less than " << b << endl;
|
||||
|
||||
// test for equality
|
||||
if (a == b)
|
||||
cout << a << " is equal to " << b << endl;
|
||||
|
||||
// test for greater-than
|
||||
if (a > b)
|
||||
cout << a << " is greater than " << b << endl;
|
||||
}
|
||||
18
Task/Integer-comparison/C/integer-comparison.c
Normal file
18
Task/Integer-comparison/C/integer-comparison.c
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int a, b;
|
||||
scanf("%d %d", &a, &b);
|
||||
|
||||
if (a < b)
|
||||
printf("%d is less than %d\n", a, b);
|
||||
|
||||
if (a == b)
|
||||
printf("%d is equal to %d\n", a, b);
|
||||
|
||||
if (a > b)
|
||||
printf("%d is greater than %d\n", a, b);
|
||||
|
||||
return 0;
|
||||
}
|
||||
19
Task/Integer-comparison/CMake/integer-comparison.cmake
Normal file
19
Task/Integer-comparison/CMake/integer-comparison.cmake
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# Define A and B as integers. For example:
|
||||
# cmake -DA=3 -DB=5 -P compare.cmake
|
||||
|
||||
# The comparisons can take variable names, or they can take numbers.
|
||||
# So these act all the same:
|
||||
# A LESS B
|
||||
# ${A} LESS ${B}
|
||||
# A LESS ${B}
|
||||
# ${A} LESS B
|
||||
|
||||
if(A LESS B)
|
||||
message(STATUS "${A} is less than ${B}")
|
||||
endif()
|
||||
if(A EQUAL B)
|
||||
message(STATUS "${A} is equal to ${B}")
|
||||
endif()
|
||||
if(A GREATER B)
|
||||
message(STATUS "${A} is greater than ${B}")
|
||||
endif()
|
||||
12
Task/Integer-comparison/Clean/integer-comparison.clean
Normal file
12
Task/Integer-comparison/Clean/integer-comparison.clean
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import StdEnv
|
||||
|
||||
compare a b
|
||||
| a < b = "A is less than B"
|
||||
| a > b = "A is more than B"
|
||||
| a == b = "A equals B"
|
||||
|
||||
Start world
|
||||
# (console, world) = stdio world
|
||||
(_, a, console) = freadi console
|
||||
(_, b, console) = freadi console
|
||||
= compare a b
|
||||
6
Task/Integer-comparison/Clojure/integer-comparison.clj
Normal file
6
Task/Integer-comparison/Clojure/integer-comparison.clj
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
(let [[a b] (repeatedly read)]
|
||||
(doseq [[op string] [[< "less than"]
|
||||
[> "greater than"]
|
||||
[= "equal to"]]]
|
||||
(when (op a b)
|
||||
(println (str a " is " string " " b)))))
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
(let ((a (read *standard-input*))
|
||||
(b (read *standard-input*)))
|
||||
(cond
|
||||
((not (numberp a)) (format t "~A is not a number." a))
|
||||
((not (numberp b)) (format t "~A is not a number." b))
|
||||
((< a b) (format t "~A is less than ~A." a b))
|
||||
((> a b) (format t "~A is greater than ~A." a b))
|
||||
((= a b) (format t "~A is equal to ~A." a b))
|
||||
(t (format t "Cannot determine relevance between ~A and ~B!" a b)))))
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
(defun compare-integers ()
|
||||
(let ((a (read *standard-input*))
|
||||
(b (read *standard-input*)))
|
||||
(cond
|
||||
((not (numberp a)) (format t "~A is not a number." a))
|
||||
((not (numberp b)) (format t "~A is not a number." b))
|
||||
((< a b) (format t "~A is less than ~A." a b))
|
||||
((> a b) (format t "~A is greater than ~A." a b))
|
||||
((= a b) (format t "~A is equal to ~A." a b))
|
||||
(t (format t "Cannot determine relevance between ~A and ~B!" a b)))))
|
||||
18
Task/Integer-comparison/D/integer-comparison.d
Normal file
18
Task/Integer-comparison/D/integer-comparison.d
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import std.stdio, std.conv, std.string;
|
||||
|
||||
void main() {
|
||||
int a = 10, b = 20;
|
||||
try {
|
||||
a = to!int(readln().strip());
|
||||
b = to!int(readln().strip());
|
||||
} catch (StdioException) {}
|
||||
|
||||
if (a < b)
|
||||
writeln(a, " is less than ", b);
|
||||
|
||||
if (a == b)
|
||||
writeln(a, " is equal to ", b);
|
||||
|
||||
if (a > b)
|
||||
writeln(a, " is greater than ", b);
|
||||
}
|
||||
11
Task/Integer-comparison/Delphi/integer-comparison.delphi
Normal file
11
Task/Integer-comparison/Delphi/integer-comparison.delphi
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
program IntegerCompare;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
var
|
||||
a, b: Integer;
|
||||
begin
|
||||
if (a < b) then Writeln(a, ' is less than ', b);
|
||||
if (a = b) then Writeln(a, ' is equal to ', b);
|
||||
if (a > b) then Writeln(a, ' is greater than ', b);
|
||||
end.
|
||||
6
Task/Integer-comparison/E/integer-comparison.e
Normal file
6
Task/Integer-comparison/E/integer-comparison.e
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
def compare(a :int, b :int) {
|
||||
println(if (a < b) { `$a < $b` } \
|
||||
else if (a <=> b) { `$a = $b` } \
|
||||
else if (a > b) { `$a > $b` } \
|
||||
else { `You're calling that an integer?` })
|
||||
}
|
||||
29
Task/Integer-comparison/Efene/integer-comparison.efene
Normal file
29
Task/Integer-comparison/Efene/integer-comparison.efene
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
compare = fn (A, B) {
|
||||
if A == B {
|
||||
io.format("~p equals ~p~n", [A, B])
|
||||
}
|
||||
else {
|
||||
ok
|
||||
}
|
||||
|
||||
if A < B {
|
||||
io.format("~p is less than ~p~n", [A, B])
|
||||
}
|
||||
else {
|
||||
ok
|
||||
}
|
||||
|
||||
if A > B {
|
||||
io.format("~p is greater than ~p~n", [A, B])
|
||||
}
|
||||
else {
|
||||
ok
|
||||
}
|
||||
}
|
||||
|
||||
@public
|
||||
run = fn () {
|
||||
compare(5, 5)
|
||||
compare(6, 5)
|
||||
compare(4, 5)
|
||||
}
|
||||
11
Task/Integer-comparison/Erlang/integer-comparison.erl
Normal file
11
Task/Integer-comparison/Erlang/integer-comparison.erl
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
main() ->
|
||||
{ok, [N]} = io:fread("First integer: ", "~d"),
|
||||
{ok, [M]} = io:fread("First integer: ", "~d"),
|
||||
if
|
||||
N < M ->
|
||||
io:format("~b is less than ~b~n",[N,M]);
|
||||
N > M ->
|
||||
io:format("~b is greater than ~b~n",[N,M]);
|
||||
N == M ->
|
||||
io:format("~b is equal to ~b~n",[N,M])
|
||||
end.
|
||||
15
Task/Integer-comparison/Euphoria/integer-comparison.euphoria
Normal file
15
Task/Integer-comparison/Euphoria/integer-comparison.euphoria
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
include get.e
|
||||
|
||||
integer a,b
|
||||
a = floor(prompt_number("a = ",{}))
|
||||
b = floor(prompt_number("b = ",{}))
|
||||
|
||||
puts(1,"a is ")
|
||||
if a < b then
|
||||
puts(1,"less then")
|
||||
elsif a = b then
|
||||
puts(1,"equal to")
|
||||
elsif a > b then
|
||||
puts(1,"grater then")
|
||||
end if
|
||||
puts(1," b")
|
||||
4
Task/Integer-comparison/FALSE/integer-comparison.false
Normal file
4
Task/Integer-comparison/FALSE/integer-comparison.false
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
^^ \$@$@$@$@\
|
||||
>[\$," is greater than "\$,]?
|
||||
\>[\$," is less than "\$,]?
|
||||
=["characters are equal"]?
|
||||
5
Task/Integer-comparison/Factor/integer-comparison.factor
Normal file
5
Task/Integer-comparison/Factor/integer-comparison.factor
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
: example ( -- )
|
||||
readln readln [ string>number ] bi@
|
||||
[ > [ "A > B" print ] when ]
|
||||
[ < [ "A < B" print ] when ]
|
||||
[ = [ "A = B" print ] when ] 2tri ;
|
||||
22
Task/Integer-comparison/Fantom/integer-comparison.fantom
Normal file
22
Task/Integer-comparison/Fantom/integer-comparison.fantom
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
class Main
|
||||
{
|
||||
public static Void main ()
|
||||
{
|
||||
try
|
||||
{
|
||||
Env.cur.out.print ("Enter number 1: ").flush
|
||||
num1 := Env.cur.in.readLine.toInt
|
||||
Env.cur.out.print ("Enter number 2: ").flush
|
||||
num2 := Env.cur.in.readLine.toInt
|
||||
|
||||
if (num1 < num2)
|
||||
echo ("$num1 is smaller than $num2")
|
||||
else if (num1 == num2)
|
||||
echo ("$num1 is equal to $num2")
|
||||
else if (num1 > num2)
|
||||
echo ("$num1 is greater than $num2")
|
||||
}
|
||||
catch (Err e)
|
||||
echo ("You must enter two integers")
|
||||
}
|
||||
}
|
||||
13
Task/Integer-comparison/Fish/integer-comparison.fish
Normal file
13
Task/Integer-comparison/Fish/integer-comparison.fish
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
l2=?vv ~< v o<
|
||||
v <>l?^"Please pre-populate the stack with the two integers."ar>l?^;
|
||||
\$:@@:@)?v v ;oanv!!!?<
|
||||
>$n" is greater than "{r>ol1=^
|
||||
/ <
|
||||
\$:@@:@=?v v ;oanv!!!?<
|
||||
>$n" is equal to "{r>ol1=^
|
||||
/ <
|
||||
\$:@@:@(?v v ;oanv!!!?<
|
||||
>$n" is smaller than "{r>ol1=^
|
||||
> v
|
||||
/oo". "nooooo" and "n$< v o<
|
||||
>"They're not equal, not greater than and not smaller than eachother... strange."ar>l?^;
|
||||
4
Task/Integer-comparison/Forth/integer-comparison.fth
Normal file
4
Task/Integer-comparison/Forth/integer-comparison.fth
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
: compare-integers ( a b -- )
|
||||
2dup < if ." a is less than b" then
|
||||
2dup > if ." a is greater than b" then
|
||||
= if ." a is equal to b" then ;
|
||||
17
Task/Integer-comparison/Fortran/integer-comparison-1.f
Normal file
17
Task/Integer-comparison/Fortran/integer-comparison-1.f
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
program arithif
|
||||
integer a, b
|
||||
|
||||
c fortran 77 I/O statements, for simplicity
|
||||
read(*,*) a, b
|
||||
|
||||
if ( a - b ) 10, 20, 30
|
||||
10 write(*,*) a, ' is less than ', b
|
||||
goto 40
|
||||
|
||||
20 write(*,*) a, ' is equal to ', b
|
||||
goto 40
|
||||
|
||||
30 write(*,*) a, ' is greater than ', b
|
||||
40 continue
|
||||
|
||||
end
|
||||
9
Task/Integer-comparison/Fortran/integer-comparison-2.f
Normal file
9
Task/Integer-comparison/Fortran/integer-comparison-2.f
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
program compare
|
||||
integer a, b
|
||||
c fortran 77 I/O statements, for simplicity
|
||||
read(*,*) a, b
|
||||
|
||||
if (a .lt. b) write(*, *) a, ' is less than ', b
|
||||
if (a .eq. b) write(*, *) a, ' is equal to ', b
|
||||
if (a .gt. b) write(*, *) a, ' is greater than ', b
|
||||
end
|
||||
13
Task/Integer-comparison/Fortran/integer-comparison-3.f
Normal file
13
Task/Integer-comparison/Fortran/integer-comparison-3.f
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
program compare
|
||||
integer a, b
|
||||
read(*,*) a, b
|
||||
|
||||
if (a .lt. b) then
|
||||
write(*, *) a, ' is less than ', b
|
||||
else if (a .eq. b) then
|
||||
write(*, *) a, ' is equal to ', b
|
||||
else if (a .gt. b) then
|
||||
write(*, *) a, ' is greater than ', b
|
||||
end if
|
||||
|
||||
end
|
||||
13
Task/Integer-comparison/Fortran/integer-comparison-4.f
Normal file
13
Task/Integer-comparison/Fortran/integer-comparison-4.f
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
program compare
|
||||
integer :: a, b
|
||||
read(*,*) a, b
|
||||
|
||||
if (a < b) then
|
||||
write(*, *) a, ' is less than ', b
|
||||
else if (a == b) then
|
||||
write(*, *) a, ' is equal to ', b
|
||||
else if (a > b) then
|
||||
write(*, *) a, ' is greater than ', b
|
||||
end if
|
||||
|
||||
end program compare
|
||||
7
Task/Integer-comparison/Frink/integer-comparison.frink
Normal file
7
Task/Integer-comparison/Frink/integer-comparison.frink
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
[a,b] = input["Enter numbers",["a","b"]]
|
||||
if a<b
|
||||
println["$a < $b"]
|
||||
if a==b
|
||||
println["$a == $b"]
|
||||
if a>b
|
||||
println["$a > $b"]
|
||||
36
Task/Integer-comparison/Go/integer-comparison.go
Normal file
36
Task/Integer-comparison/Go/integer-comparison.go
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"bufio"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
in := bufio.NewReader(os.Stdin)
|
||||
getInt := func() int {
|
||||
fmt.Print("Integer: ")
|
||||
s, err := in.ReadString('\n')
|
||||
if err != nil {
|
||||
fmt.Println("\nComputer says input error")
|
||||
os.Exit(0)
|
||||
}
|
||||
i, err := strconv.Atoi(strings.TrimSpace(s))
|
||||
if err != nil {
|
||||
fmt.Println("Not an integer")
|
||||
os.Exit(0)
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
n1 := getInt()
|
||||
n2 := getInt()
|
||||
|
||||
switch {
|
||||
case n1 < n2: fmt.Println(n1, "less than", n2)
|
||||
case n1 == n2: fmt.Println(n1, "equal to", n2)
|
||||
case n1 > n2: fmt.Println(n1, "greater than", n2)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
def comparison = { a, b ->
|
||||
println "a ? b = ${a} ? ${b} = a ${a < b ? '<' : a > b ? '>' : a == b ? '==' : '?'} b"
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
comparison(2000,3)
|
||||
comparison(2000,300000)
|
||||
comparison(2000,2000)
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
def comparison = { a, b ->
|
||||
def rels = [ (-1) : '<', 0 : '==', 1 : '>' ]
|
||||
println "a ? b = ${a} ? ${b} = a ${rels[a <=> b]} b"
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
comparison(2000,3)
|
||||
comparison(2000,300000)
|
||||
comparison(2000,2000)
|
||||
11
Task/Integer-comparison/Haskell/integer-comparison-1.hs
Normal file
11
Task/Integer-comparison/Haskell/integer-comparison-1.hs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
myCompare a b
|
||||
| a < b = "A is less than B"
|
||||
| a > b = "A is greater than B"
|
||||
| a == b = "A equals B"
|
||||
|
||||
main = do
|
||||
a' <- getLine
|
||||
b' <- getLine
|
||||
let { a :: Integer; a = read a' }
|
||||
let { b :: Integer; b = read b' }
|
||||
putStrLn $ myCompare a b
|
||||
4
Task/Integer-comparison/Haskell/integer-comparison-2.hs
Normal file
4
Task/Integer-comparison/Haskell/integer-comparison-2.hs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
myCompare a b = case compare a b of
|
||||
LT -> "A is less than B"
|
||||
GT -> "A is greater than B"
|
||||
EQ -> "A equals B"
|
||||
9
Task/Integer-comparison/HicEst/integer-comparison.hicest
Normal file
9
Task/Integer-comparison/HicEst/integer-comparison.hicest
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
DLG(NameEdit=a, NameEdit=b, Button='OK')
|
||||
|
||||
IF (a < b) THEN
|
||||
WRITE(Messagebox) a, ' is less than ', b
|
||||
ELSEIF(a == b) THEN
|
||||
WRITE(Messagebox) a, ' is equal to ', b
|
||||
ELSEIF(a > b) THEN
|
||||
WRITE(Messagebox) a, ' is greater than ', b
|
||||
ENDIF
|
||||
16
Task/Integer-comparison/Icon/integer-comparison.icon
Normal file
16
Task/Integer-comparison/Icon/integer-comparison.icon
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
procedure main()
|
||||
|
||||
until integer(a) do {
|
||||
writes("Enter the first integer a := ")
|
||||
write(a := read())
|
||||
}
|
||||
|
||||
until integer(b) do {
|
||||
writes("Enter the second integer b := ")
|
||||
write(b := read())
|
||||
}
|
||||
writes("Then ")
|
||||
write(a," < ", a < b)
|
||||
write(a," = ", a = b)
|
||||
write(a," > ", a > b)
|
||||
end
|
||||
7
Task/Integer-comparison/J/integer-comparison-1.j
Normal file
7
Task/Integer-comparison/J/integer-comparison-1.j
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
compare=: < , = , >
|
||||
|
||||
cti=: dyad define
|
||||
select =. ;@#
|
||||
English =. ' is less than ';' is equal to ';' is greater than '
|
||||
x (":@[, (compare select English"_), ":@]) y
|
||||
)
|
||||
4
Task/Integer-comparison/J/integer-comparison-2.j
Normal file
4
Task/Integer-comparison/J/integer-comparison-2.j
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
4 compare 4
|
||||
0 1 0
|
||||
4 cti 3
|
||||
4 is greater than 3
|
||||
21
Task/Integer-comparison/Java/integer-comparison.java
Normal file
21
Task/Integer-comparison/Java/integer-comparison.java
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import java.io.*;
|
||||
|
||||
public class compInt {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
|
||||
|
||||
int nbr1 = Integer.parseInt(in.readLine());
|
||||
int nbr2 = Integer.parseInt(in.readLine());
|
||||
|
||||
if(nbr1<nbr2)
|
||||
System.out.println(nbr1 + " is less than " + nbr2);
|
||||
|
||||
if(nbr1>nbr2)
|
||||
System.out.println(nbr1 + " is greater than " + nbr2);
|
||||
|
||||
if(nbr1==nbr2)
|
||||
System.out.println(nbr1 + " is equal to " + nbr2);
|
||||
} catch(IOException e) { }
|
||||
}
|
||||
}
|
||||
26
Task/Integer-comparison/JavaScript/integer-comparison.js
Normal file
26
Task/Integer-comparison/JavaScript/integer-comparison.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// Using type coercion
|
||||
function compare(a, b) {
|
||||
if (a==b) print(a + " equals " + b);
|
||||
if (a < b) print(a + " is less than " + b);
|
||||
if (a > b) print(a + " is greater than " + b);
|
||||
}
|
||||
|
||||
// Without using type coercion and using standards
|
||||
// Written for browsers
|
||||
// assumption of a and b are both integers if typeof test passes
|
||||
function compare (a, b) {
|
||||
if (typeof a === typeof b) {
|
||||
if (a === b) {
|
||||
document.writeln(a + " equals " + b);
|
||||
}
|
||||
if (a < b) {
|
||||
document.writeln(a + " is less than " + b);
|
||||
}
|
||||
if (a > b) {
|
||||
document.writeln(a + " is greater than " + b);
|
||||
}
|
||||
} else {
|
||||
// "1" and 1 are an example of this as the first is type string and the second is type number
|
||||
print(a + "{" + (typeof a) + "} and " + b + "{" + (typeof b) + "} are not of the same type 4and cannot be compared.");
|
||||
}
|
||||
}
|
||||
21
Task/Integer-comparison/Joy/integer-comparison.joy
Normal file
21
Task/Integer-comparison/Joy/integer-comparison.joy
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#!/usr/local/bin/joy.exe
|
||||
DEFINE
|
||||
prompt == "Please enter a number and <Enter>: " putchars;
|
||||
newline == '\n putch;
|
||||
putln == put newline.
|
||||
|
||||
stdin # F
|
||||
prompt fgets # S F
|
||||
10 strtol # A F
|
||||
swap # F A
|
||||
dupd # F A A
|
||||
prompt fgets # S F A A
|
||||
10 strtol # B F A A
|
||||
popd # B A A
|
||||
dup # B B A A
|
||||
rollup # B A B A
|
||||
[<] [swap put "is less than " putchars putln] [] ifte
|
||||
[=] [swap put "is equal to " putchars putln] [] ifte
|
||||
[>] [swap put "is greater than " putchars putln] [] ifte
|
||||
# B A
|
||||
quit.
|
||||
91
Task/Integer-comparison/LLVM/integer-comparison.llvm
Normal file
91
Task/Integer-comparison/LLVM/integer-comparison.llvm
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
; ModuleID = 'test.o'
|
||||
;e means little endian
|
||||
;p: { pointer size : pointer abi : preferred alignment for pointers }
|
||||
;i same for integers
|
||||
;v is for vectors
|
||||
;f for floats
|
||||
;a for aggregate types
|
||||
;s for stack objects
|
||||
;n: {size:size:size...}, best integer sizes
|
||||
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
|
||||
;this was compiled with mingw32; thus it must be linked to a compatible c library
|
||||
target triple = "i386-mingw32"
|
||||
|
||||
; Declare string constants
|
||||
@.str = private constant [6 x i8] c"%d %d\00", align 1 ; <[6 x i8]*> [#uses=1]
|
||||
@.str1 = private constant [20 x i8] c"%d is less than %d\0A\00", align 1 ; <[20 x i8]*> [#uses=1]
|
||||
@.str2 = private constant [19 x i8] c"%d is equal to %d\0A\00", align 1 ; <[19 x i8]*> [#uses=1]
|
||||
@.str3 = private constant [23 x i8] c"%d is greater than %d\0A\00", align 1 ; <[23 x i8]*> [#uses=1]
|
||||
|
||||
;Declare main function (entry point). It does not throw any exceptions, and returns an integer of size 32.
|
||||
define i32 @main() nounwind {
|
||||
;Entry block
|
||||
entry:
|
||||
;Allocate the first integer, register %a will point to that
|
||||
%a = alloca i32, align 4 ; <i32*> [#uses=4]
|
||||
;Allocate the second integer, register %b will point to that
|
||||
%b = alloca i32, align 4 ; <i32*> [#uses=4]
|
||||
;Use the C standard library function scanf() to obtain input from users.
|
||||
;Scanf takes a pointer to the string constant @.str, "%d %d\00", which will take two integers from the user.
|
||||
;getelementptr basically does pointer math, in this case, no ptr math is required (we point to the beginning of @.str).
|
||||
;Pass %a and %b, which are pointers to integers allocated previously.
|
||||
;Scanf will store the two integers into the memory locations represented by %a and %b
|
||||
%0 = call i32 (i8*, ...)* @scanf(i8* noalias getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0), i32* %a, i32* %b) nounwind ; <i32> [#uses=0]
|
||||
;Load the integer pointed to by %a and %b into registers %1 and %2 respectively
|
||||
%1 = load i32* %a, align 4 ; <i32> [#uses=3]
|
||||
%2 = load i32* %b, align 4 ; <i32> [#uses=3]
|
||||
;Boolean register which represents if %1 is less than to %2
|
||||
%3 = icmp slt i32 %1, %2 ; <i1> [#uses=1]
|
||||
;If %1 is less than to %2, goto branch %bb, otherwise, goto %bb1
|
||||
br i1 %3, label %bb, label %bb1
|
||||
|
||||
;If integer %1 is less than %2
|
||||
bb: ; preds = %entry
|
||||
;Use the C standard library function printf to output information to users
|
||||
;Print @.str1, "%d is less than %d\0A\00"
|
||||
;Additionally, pass the integers %1 and %2 to printf, to be formatted into the string
|
||||
%4 = call i32 (i8*, ...)* @printf(i8* noalias getelementptr inbounds ([20 x i8]* @.str1, i32 0, i32 0), i32 %1, i32 %2) nounwind ; <i32> [#uses=0]
|
||||
;Continue on to %bb1, to check for equality of the two integers
|
||||
br label %bb1
|
||||
|
||||
;Continue checking if the integers are equal
|
||||
bb1: ; preds = %bb, %entry
|
||||
;Boolean register which represents if %1 is equal to %2
|
||||
%5 = icmp eq i32 %1, %2 ; <i1> [#uses=1]
|
||||
;If %1 is equal to %2, goto branch %bb2, otherwise, goto %bb3
|
||||
br i1 %5, label %bb2, label %bb3
|
||||
|
||||
;If integer %1 is equal to %2
|
||||
bb2: ; preds = %bb1
|
||||
;Use the C standard library function printf to output information to users
|
||||
;Print @.str2 "%d is equal to %d\0A\00"
|
||||
;Additionally, pass the integers %1 and %2 to printf, to be formatted into the string
|
||||
%6 = call i32 (i8*, ...)* @printf(i8* noalias getelementptr inbounds ([19 x i8]* @.str2, i32 0, i32 0), i32 %1, i32 %2) nounwind ; <i32> [#uses=0]
|
||||
;Continue on to %bb3, to check if %1 is greater than %2
|
||||
br label %bb3
|
||||
|
||||
;Continue checking if %1 is greater than %2
|
||||
bb3: ; preds = %bb2, %bb1
|
||||
;Boolean register which represents if %1 is greater than %2
|
||||
%7 = icmp sgt i32 %1, %2 ; <i1> [#uses=1]
|
||||
;If %1 is greather than %2, goto branch %bb4, otherwise, goto %bb5
|
||||
br i1 %7, label %bb4, label %bb5
|
||||
|
||||
;If integer %1 is greater than %2
|
||||
bb4: ; preds = %bb3
|
||||
;Use the C standard library function printf to output information to users
|
||||
;Print @.str3 "%d is greater than %d\0A\00"
|
||||
;Additionally, pass the integers %1 and %2 to printf, to be formatted into the string
|
||||
%8 = call i32 (i8*, ...)* @printf(i8* noalias getelementptr inbounds ([23 x i8]* @.str3, i32 0, i32 0), i32 %1, i32 %2) nounwind ; <i32> [#uses=0]
|
||||
;Return 0 for the main function, indicating program executed successfully
|
||||
ret i32 0
|
||||
|
||||
bb5: ; preds = %bb3
|
||||
;Return 0 for the main function, indicating program executed successfully
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
;Declare external fuctions
|
||||
declare i32 @scanf(i8* nocapture, ...) nounwind
|
||||
|
||||
declare i32 @printf(i8* nocapture, ...) nounwind
|
||||
8
Task/Integer-comparison/LSE64/integer-comparison.lse64
Normal file
8
Task/Integer-comparison/LSE64/integer-comparison.lse64
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
over : 2 pick
|
||||
2dup : over over
|
||||
|
||||
compare : 2dup = then " equals"
|
||||
compare : 2dup < then " is less than"
|
||||
compare : 2dup > then " is more than"
|
||||
|
||||
show : compare rot , sp ,t sp , nl
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
input "Enter an integer for a. ";a
|
||||
input "Enter an integer for b. ";b
|
||||
|
||||
'a=int(a):b=int(b) ???
|
||||
print "Conditional evaluation."
|
||||
if a<b then print "a<b " ; a ; " < " ; b
|
||||
if a=b then print "a=b " ; a ; " = " ; b
|
||||
if a>b then print "a>b " ; a ; " > " ; b
|
||||
|
||||
print "Select case evaluation."
|
||||
select case
|
||||
case (a<b)
|
||||
print "a<b " ; a ; " < " ; b
|
||||
case (a=b)
|
||||
print "a=b " ; a ; " = " ; b
|
||||
case (a>b)
|
||||
print "a>b " ; a ; " > " ; b
|
||||
end select
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
input "Enter an integer for a. ";a
|
||||
input "Enter an integer for b. ";b
|
||||
|
||||
for i = 1 to 3
|
||||
op$=word$("< = >", i)
|
||||
if eval("a"+op$+"b") then print "a"+op$+"b " ; a;" ";op$;" ";b
|
||||
next
|
||||
5
Task/Integer-comparison/Logo/integer-comparison.logo
Normal file
5
Task/Integer-comparison/Logo/integer-comparison.logo
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
to compare :a :b
|
||||
if :a = :b [(print :a [equals] :b)]
|
||||
if :a < :b [(print :a [is less than] :b)]
|
||||
if :a > :b [(print :a [is greater than] :b)]
|
||||
end
|
||||
8
Task/Integer-comparison/Lua/integer-comparison-1.lua
Normal file
8
Task/Integer-comparison/Lua/integer-comparison-1.lua
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
print('Enter the first number: ')
|
||||
a = tonumber(io.stdin:read())
|
||||
print('Enter the second number: ')
|
||||
b = tonumber(io.stdin:read())
|
||||
|
||||
if a < b then print(a .. " is less than " .. b) end
|
||||
if a > b then print(a .. " is greater than " .. b) end
|
||||
if a == b then print(a .. " is equal to " .. b) end
|
||||
1
Task/Integer-comparison/Lua/integer-comparison-2.lua
Normal file
1
Task/Integer-comparison/Lua/integer-comparison-2.lua
Normal file
|
|
@ -0,0 +1 @@
|
|||
-- if a = b then print("This will not work")
|
||||
5
Task/Integer-comparison/MAXScript/integer-comparison.max
Normal file
5
Task/Integer-comparison/MAXScript/integer-comparison.max
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
a = getKBValue prompt:"Enter value of a:"
|
||||
b = getKBValue prompt:"Enter value of b:"
|
||||
if a < b then print "a is less then b"
|
||||
else if a > b then print "a is greater then b"
|
||||
else if a == b then print "a is equal to b"
|
||||
18
Task/Integer-comparison/ML-I/integer-comparison.ml
Normal file
18
Task/Integer-comparison/ML-I/integer-comparison.ml
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
"" Integer comparison
|
||||
"" assumes macros on input stream 1, terminal on stream 2
|
||||
MCSKIP MT,<>
|
||||
MCSKIP SL WITH ~
|
||||
MCINS %.
|
||||
MCDEF SL SPACES NL AS <MCSET T1=%A1.
|
||||
MCSET T2=%A2.
|
||||
MCGO L1 UNLESS T1 EN T2
|
||||
%A1. is equal to %A2.
|
||||
%L1.MCGO L2 UNLESS %A1. GR %A2.
|
||||
%A1. is greater than %A2.
|
||||
%L2.MCGO L3 IF %A1. GE %A2.
|
||||
%A1. is less than %A2.
|
||||
%L3.
|
||||
MCSET S10=0
|
||||
>
|
||||
MCSET S1=1
|
||||
~MCSET S10=2
|
||||
85
Task/Integer-comparison/MMIX/integer-comparison.mmix
Normal file
85
Task/Integer-comparison/MMIX/integer-comparison.mmix
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
// main registers
|
||||
p IS $255 % pointer
|
||||
pp GREG % backup for p
|
||||
A GREG % first int
|
||||
B GREG % second int
|
||||
|
||||
// arg registers
|
||||
argc IS $0
|
||||
argv IS $1
|
||||
|
||||
LOC Data_Segment
|
||||
GREG @
|
||||
ERR BYTE "Wrong number of arguments",#a,0
|
||||
ILLH BYTE "Argument -> ",0
|
||||
ILLT BYTE " <- contains an illegal character",#a,0
|
||||
LT BYTE "A is less than B",#a,0
|
||||
EQ BYTE "A equals B",#a,0
|
||||
GT BYTE "A is greater than B",#a,0
|
||||
|
||||
LOC #1000
|
||||
GREG @
|
||||
// call: p points to the start of a 0-terminated numeric string
|
||||
// leading chars + and - are allowed
|
||||
// reg $72 0 if negative int
|
||||
// reg $73 gen. purpose
|
||||
// return: reg $70 contains integer value
|
||||
readInt XOR $70,$70,$70 % reset result reg: N=0.
|
||||
LDA pp,p % remember &p
|
||||
LDBU $72,p
|
||||
CMP $73,$72,'+' % ignore '+'
|
||||
BZ $73,2F
|
||||
CMP $72,$72,'-'
|
||||
BNZ $72,1F
|
||||
2H INCL p,1
|
||||
JMP 1F
|
||||
% repeat
|
||||
3H CMP $73,$71,'0' % if c < '0' or c > '9'
|
||||
BN $73,4F % then print err and halt program
|
||||
CMP $73,$71,'9'
|
||||
BP $73,4F
|
||||
SUB $71,$71,'0' % 'extract' number
|
||||
MUL $70,$70,10
|
||||
ADD $70,$70,$71 % N = 10 * N + digit
|
||||
INCL p,1
|
||||
1H LDBU $71,p % get next digit
|
||||
PBNZ $71,3B % until end of string
|
||||
CMP $72,$72,0
|
||||
BNZ $72,2F % if marked negative
|
||||
NEG $70,$70 % then make negative
|
||||
2H GO $127,$127,0 % return (N)
|
||||
|
||||
4H LDA p,ILLH
|
||||
TRAP 0,Fputs,StdErr
|
||||
LDA p,pp
|
||||
TRAP 0,Fputs,StdErr
|
||||
LDA p,ILLT
|
||||
TRAP 0,Fputs,StdErr
|
||||
TRAP 0,Halt,0
|
||||
|
||||
// entrance of program
|
||||
// e.g. ~> mmix compare2ints A B
|
||||
//
|
||||
Main CMP p,argc,3 % main (argc, argv) {
|
||||
BZ p,1F % if argc == 3 then continue
|
||||
LDA p,ERR % else print wrong number of args
|
||||
TRAP 0,Fputs,StdErr
|
||||
TRAP 0,Halt,0
|
||||
// get ints A and B
|
||||
1H LDOU p,argv,8 % fetch addres of first int
|
||||
GO $127,readInt % read int A
|
||||
ADD A,$70,0
|
||||
|
||||
LDOU p,argv,16
|
||||
GO $127,readInt % read int B
|
||||
ADD B,$70,0
|
||||
|
||||
// perform comparison
|
||||
CMP A,A,B % case compare A B
|
||||
LDA p,LT
|
||||
BN A,2F % LT: print 'LT'
|
||||
LDA p,EQ
|
||||
BZ A,2F % EQ: print 'EQ'
|
||||
LDA p,GT % _ : print 'GT'
|
||||
2H TRAP 0,Fputs,StdOut % print result
|
||||
TRAP 0,Halt,0
|
||||
11
Task/Integer-comparison/MUMPS/integer-comparison.mumps
Normal file
11
Task/Integer-comparison/MUMPS/integer-comparison.mumps
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
INTCOMP
|
||||
NEW A,B
|
||||
INTCOMPREAD
|
||||
READ !,"Enter an integer to test: ",A
|
||||
READ !,"Enter another integer: ",B
|
||||
IF (+A\1'=A)!(+B\1'=B) WRITE !!,"Please enter two integers.",! GOTO INTCOMPREAD
|
||||
IF A<B WRITE !,A," is less than ",B
|
||||
IF A=B WRITE !,A," is equal to ",B
|
||||
IF A>B WRITE !,A," is greater than ",B
|
||||
KILL A,B
|
||||
QUIT
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
a=Input["Give me the value for a please!"];
|
||||
b=Input["Give me the value for b please!"];
|
||||
If[a==b,Print["a equals b"]]
|
||||
If[a>b,Print["a is bigger than b"]]
|
||||
If[a<b,Print["b is bigger than a"]]
|
||||
9
Task/Integer-comparison/Maxima/integer-comparison.maxima
Normal file
9
Task/Integer-comparison/Maxima/integer-comparison.maxima
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/* all 6 comparison operators (last is "not equal") */
|
||||
block(
|
||||
[a: read("a?"), b: read("b?")],
|
||||
if a < b then print(a, "<", b),
|
||||
if a <= b then print(a, "<=", b),
|
||||
if a > b then print(a, ">", b),
|
||||
if a >= b then print(a, ">=", b),
|
||||
if a = b then print(a, "=", b),
|
||||
if a # b then print(a, "#", b))$
|
||||
12
Task/Integer-comparison/Metafont/integer-comparison.metafont
Normal file
12
Task/Integer-comparison/Metafont/integer-comparison.metafont
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
message "integer 1: ";
|
||||
a1 := scantokens readstring;
|
||||
message "integer 2: ";
|
||||
a2 := scantokens readstring;
|
||||
if a1 < a2:
|
||||
message decimal a1 & " is less than " & decimal a2
|
||||
elseif a1 > a2:
|
||||
message decimal a1 & " is greater than " & decimal a2
|
||||
elseif a1 = a2:
|
||||
message decimal a1 & " is equal to " & decimal a2
|
||||
fi;
|
||||
end
|
||||
22
Task/Integer-comparison/Modula-2/integer-comparison.mod2
Normal file
22
Task/Integer-comparison/Modula-2/integer-comparison.mod2
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
MODULE IntCompare;
|
||||
|
||||
IMPORT InOut;
|
||||
|
||||
VAR
|
||||
A, B: INTEGER;
|
||||
|
||||
BEGIN
|
||||
InOut.ReadInt(A);
|
||||
InOut.ReadInt(B);
|
||||
InOut.WriteInt(A, 1);
|
||||
|
||||
IF A < B THEN
|
||||
InOut.WriteString(' is less than ')
|
||||
ELSIF A = B THEN
|
||||
InOut.WriteString(' is equal to ')
|
||||
ELSE
|
||||
InOut.WriteString(' is greater than ')
|
||||
END;
|
||||
InOut.WriteInt(B, 1);
|
||||
InOut.WriteLn
|
||||
END IntCompare.
|
||||
18
Task/Integer-comparison/Modula-3/integer-comparison.mod3
Normal file
18
Task/Integer-comparison/Modula-3/integer-comparison.mod3
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
MODULE Main;
|
||||
|
||||
FROM IO IMPORT Put, GetInt;
|
||||
FROM Fmt IMPORT Int;
|
||||
|
||||
VAR a,b: INTEGER;
|
||||
|
||||
BEGIN
|
||||
a := GetInt();
|
||||
b := GetInt();
|
||||
IF a < b THEN
|
||||
Put(Int(a) & " is less than " & Int(b) & "\n");
|
||||
ELSIF a = b THEN
|
||||
Put(Int(a) & " is equal to " & Int(b) & "\n");
|
||||
ELSIF a > b THEN
|
||||
Put(Int(a) & " is greater than " & Int(b) & "\n");
|
||||
END;
|
||||
END Main.
|
||||
27
Task/Integer-comparison/PHP/integer-comparison.php
Normal file
27
Task/Integer-comparison/PHP/integer-comparison.php
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
echo "Enter an integer [int1]: ";
|
||||
fscanf(STDIN, "%d\n", $int1);
|
||||
if(!is_numeric($int1)) {
|
||||
echo "Invalid input; terminating.\n";
|
||||
exit(1); // return w/ general error
|
||||
}
|
||||
|
||||
echo "Enter an integer [int2]: ";
|
||||
fscanf(STDIN, "%d\n", $int2);
|
||||
if(!is_numeric($int2)) {
|
||||
echo "Invalid input; terminating.\n";
|
||||
exit(1); // return w/ general error
|
||||
}
|
||||
|
||||
// now $int1 and $int2 are numbers.
|
||||
// for simplicity, this does not explicitly examine types
|
||||
|
||||
if($int1 < $int2)
|
||||
echo "int1 < int2\n";
|
||||
if($int1 == $int2)
|
||||
echo "int1 = int2\n";
|
||||
if($int1 > $int2)
|
||||
echo "int1 > int2\n";
|
||||
|
||||
?>
|
||||
13
Task/Integer-comparison/Perl/integer-comparison-1.pl
Normal file
13
Task/Integer-comparison/Perl/integer-comparison-1.pl
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
sub test_num {
|
||||
my $f = shift;
|
||||
my $s = shift;
|
||||
if ($f < $s){
|
||||
return -1; # returns -1 if $f is less than $s
|
||||
} elsif ($f > $s) {
|
||||
return 1; # returns 1 if $f is greater than $s
|
||||
} elsif ($f == $s) {
|
||||
# = operator is an assignment
|
||||
# == operator is a numeric comparison
|
||||
return 0; # returns 0 $f is equal to $s
|
||||
};
|
||||
};
|
||||
3
Task/Integer-comparison/Perl/integer-comparison-2.pl
Normal file
3
Task/Integer-comparison/Perl/integer-comparison-2.pl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
sub test_num {
|
||||
return $_[0] <=> $_[1];
|
||||
};
|
||||
5
Task/Integer-comparison/Perl/integer-comparison-3.pl
Normal file
5
Task/Integer-comparison/Perl/integer-comparison-3.pl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# Get input, test and display
|
||||
print "Enter two integers: ";
|
||||
($x, $y) = split ' ', <>;
|
||||
print $x, (" is less than ", " is equal to ",
|
||||
" is greater than ")[test_num($x, $y) + 1], $y, "\n";
|
||||
11
Task/Integer-comparison/PicoLisp/integer-comparison.l
Normal file
11
Task/Integer-comparison/PicoLisp/integer-comparison.l
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
(prin "Please enter two values: ")
|
||||
|
||||
(in NIL # Read from standard input
|
||||
(let (A (read) B (read))
|
||||
(prinl
|
||||
"The first one is "
|
||||
(cond
|
||||
((> A B) "greater than")
|
||||
((= A B) "equal to")
|
||||
(T "less than") )
|
||||
" the second." ) ) )
|
||||
10
Task/Integer-comparison/Python/integer-comparison-1.py
Normal file
10
Task/Integer-comparison/Python/integer-comparison-1.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#!/usr/bin/env python
|
||||
a = int(raw_input('Enter value of a: '))
|
||||
b = int(raw_input('Enter value of b: '))
|
||||
|
||||
if a < b:
|
||||
print 'a is less than b'
|
||||
elif a > b:
|
||||
print 'a is greater than b'
|
||||
elif a == b:
|
||||
print 'a is equal to b'
|
||||
15
Task/Integer-comparison/Python/integer-comparison-2.py
Normal file
15
Task/Integer-comparison/Python/integer-comparison-2.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
try:
|
||||
a = int(raw_input('Enter value of a: '))
|
||||
b = int(raw_input('Enter value of b: '))
|
||||
except (ValueError, EnvironmentError), err:
|
||||
print sys.stderr, "Erroneous input:", err
|
||||
sys.exit(1)
|
||||
|
||||
dispatch = {
|
||||
-1: 'is less than',
|
||||
0: 'is equal to',
|
||||
1: 'is greater than'
|
||||
}
|
||||
print a, dispatch[cmp(a,b)], b
|
||||
11
Task/Integer-comparison/R/integer-comparison.r
Normal file
11
Task/Integer-comparison/R/integer-comparison.r
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
print("insert number a")
|
||||
a <- scan(what=numeric(0), nmax=1)
|
||||
print("insert number b")
|
||||
b <- scan(what=numeric(0), nmax=1)
|
||||
if ( a < b ) {
|
||||
print("a is less than b")
|
||||
} else if ( a > b ) {
|
||||
print("a is greater than b")
|
||||
} else if ( a == b ) { # could be simply else of course...
|
||||
print("a and b are the same")
|
||||
}
|
||||
25
Task/Integer-comparison/REXX/integer-comparison.rexx
Normal file
25
Task/Integer-comparison/REXX/integer-comparison.rexx
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/*REXX program prompts for two integers, compares 'em, tells results. */
|
||||
numeric digits 1000 /*for the users that go ka-razy. */
|
||||
a=getInt('─────── Please enter your first integer:') /*get 1st integer.*/
|
||||
b=getInt('─────── Please enter your second integer:') /*get 2nd integer.*/
|
||||
|
||||
if a<b then say a ' is less than ' b
|
||||
if a=b then say a ' is equal to ' b
|
||||
if a>b then say a ' is greater than ' b
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────GETINT subroutine───────────────────*/
|
||||
getInt: procedure /*prompt the CBLF, get an integer*/
|
||||
/*¬geeks: Carbon-Based Life Form.*/
|
||||
do forever /*keep prompting until success. */
|
||||
say; say arg(1) /*display the prompt message. */
|
||||
parse pull x /*get X, and keep its case intact*/
|
||||
select
|
||||
when x='' then call serr 'Nothing was entered.'
|
||||
when words(x)>1 then call serr 'Too many arguments entered.'
|
||||
when \datatype(x,'N') then call serr "Argument isn't numeric:" x
|
||||
when \datatype(x,'W') then call serr "Argument isn't an integer:" x
|
||||
otherwise return x /*Eureka! Return X to invoker.*/
|
||||
end /*select*/
|
||||
end /*forever*/
|
||||
/*──────────────────────────────────SERR subroutine─────────────────────*/
|
||||
serr: say '***error!*** ' arg(1); say "Please try again."; return
|
||||
6
Task/Integer-comparison/Ruby/integer-comparison-1.rb
Normal file
6
Task/Integer-comparison/Ruby/integer-comparison-1.rb
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
a = (print "enter a value for a: "; gets).to_i
|
||||
b = (print "enter a value for b: "; gets).to_i
|
||||
|
||||
puts "#{a} is less than #{b}" if a < b
|
||||
puts "#{a} is greater than #{b}" if a > b
|
||||
puts "#{a} is equal to #{b}" if a == b
|
||||
8
Task/Integer-comparison/Ruby/integer-comparison-2.rb
Normal file
8
Task/Integer-comparison/Ruby/integer-comparison-2.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
a = (print "enter a value for a: "; gets).to_i
|
||||
b = (print "enter a value for b: "; gets).to_i
|
||||
|
||||
case a <=> b
|
||||
when -1; puts "#{a} is less than #{b}"
|
||||
when 0; puts "#{a} is equal to #{b}"
|
||||
when +1; puts "#{a} is greater than #{b}"
|
||||
end
|
||||
24
Task/Integer-comparison/Ruby/integer-comparison-3.rb
Normal file
24
Task/Integer-comparison/Ruby/integer-comparison-3.rb
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# Function to make prompts nice and simple to abuse
|
||||
def prompt str
|
||||
print str, ": "
|
||||
gets.chomp
|
||||
end
|
||||
|
||||
# Get value of a
|
||||
a = prompt('Enter value of a').to_i
|
||||
# Get value of b
|
||||
b = prompt('Enter value of b').to_i
|
||||
|
||||
# The dispatch hash uses the <=> operator
|
||||
# When doing x<=>y:
|
||||
# -1 means x is less than y
|
||||
# 0 means x is equal to y
|
||||
# 1 means x is greater than y
|
||||
dispatch = {
|
||||
-1 => "less than",
|
||||
0 => "equal to",
|
||||
1 => "greater than"
|
||||
}
|
||||
|
||||
# I hope you can figure this out
|
||||
puts "#{a} is #{dispatch[a<=>b]} #{b}"
|
||||
4
Task/Integer-comparison/SNUSP/integer-comparison.snusp
Normal file
4
Task/Integer-comparison/SNUSP/integer-comparison.snusp
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
++++>++++ a b !/?\<?\# a=b
|
||||
> - \# a>b
|
||||
- <
|
||||
a<b #\?/
|
||||
12
Task/Integer-comparison/Scala/integer-comparison.scala
Normal file
12
Task/Integer-comparison/Scala/integer-comparison.scala
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
object IntCompare {
|
||||
def main(args: Array[String]): Unit = {
|
||||
val a=Console.readInt
|
||||
val b=Console.readInt
|
||||
if (a < b)
|
||||
printf("%d is less than %d\n", a, b)
|
||||
if (a == b)
|
||||
printf("%d is equal to %d\n", a, b)
|
||||
if (a > b)
|
||||
printf("%d is greater than %d\n", a, b)
|
||||
}
|
||||
}
|
||||
6
Task/Integer-comparison/Scheme/integer-comparison.ss
Normal file
6
Task/Integer-comparison/Scheme/integer-comparison.ss
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
(define (my-compare a b)
|
||||
(cond ((< a b) "A is less than B")
|
||||
((> a b) "A is greater than B")
|
||||
((= a b) "A equals B")))
|
||||
|
||||
(my-compare (read) (read))
|
||||
6
Task/Integer-comparison/Smalltalk/integer-comparison.st
Normal file
6
Task/Integer-comparison/Smalltalk/integer-comparison.st
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
| a b |
|
||||
'a = ' display. a := (stdin nextLine asInteger).
|
||||
'b = ' display. b := (stdin nextLine asInteger).
|
||||
( a > b ) ifTrue: [ 'a greater than b' displayNl ].
|
||||
( a < b ) ifTrue: [ 'a less than b' displayNl ].
|
||||
( a = b ) ifTrue: [ 'a is equal to b' displayNl ].
|
||||
8
Task/Integer-comparison/Tcl/integer-comparison-1.tcl
Normal file
8
Task/Integer-comparison/Tcl/integer-comparison-1.tcl
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
puts "Please enter two numbers:"
|
||||
|
||||
gets stdin x
|
||||
gets stdin y
|
||||
|
||||
if { $x > $y } { puts "$x is greater than $y" }
|
||||
if { $x < $y } { puts "$x is less than $y" }
|
||||
if { $x == $y } { puts "$x equals $y" }
|
||||
1
Task/Integer-comparison/Tcl/integer-comparison-2.tcl
Normal file
1
Task/Integer-comparison/Tcl/integer-comparison-2.tcl
Normal file
|
|
@ -0,0 +1 @@
|
|||
if {int($x) > int($y)} { puts "$x is greater than $y" }
|
||||
9
Task/Integer-comparison/Tcl/integer-comparison-3.tcl
Normal file
9
Task/Integer-comparison/Tcl/integer-comparison-3.tcl
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
% set i 5;set j 6
|
||||
% foreach {o s} {< "less than" > "greater than" == equal} {if [list $i $o $j] {puts "$i is $s $j"}}
|
||||
5 is less than 6
|
||||
% set j 5
|
||||
% foreach {o s} {< "less than" > "greater than" == equal} {if [list $i $o $j] {puts "$i is $s $j"}}
|
||||
5 is equal 5
|
||||
% set j 4
|
||||
% foreach {o s} {< "less than" > "greater than" == equal} {if [list $i $o $j] {puts "$i is $s $j"}}
|
||||
5 is greater than 4
|
||||
Loading…
Add table
Add a link
Reference in a new issue