Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,3 +1,5 @@
|
|||
{{basic data operation}}Get two integers from the user, and then output if the first one is less than, equal to, or greater than the other. Test the condition ''for each case separately'', so that ''all three comparison operators are used'' in the code.
|
||||
{{basic data operation}} [[Category:Simple]]
|
||||
Get two integers from the user, and then output if the first one is less than, equal to, 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]]
|
||||
See also: [[String comparison]]
|
||||
|
|
|
|||
33
Task/Integer-comparison/360-Assembly/integer-comparison.360
Normal file
33
Task/Integer-comparison/360-Assembly/integer-comparison.360
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
INTCOMP PROLOG
|
||||
* Reg1=Addr(Addr(argA),Addr(argB))
|
||||
L 2,0(1) Reg2=Addr(argA)
|
||||
L 3,4(1) Reg3=Addr(argB)
|
||||
L 4,0(2) Reg4=argA
|
||||
L 5,0(3) Reg5=argA
|
||||
ST 4,A Store R4 in A
|
||||
ST 5,B Store R5 in B
|
||||
* if (A < B)
|
||||
L 0,A load R0
|
||||
C 0,B compare
|
||||
BL LOWER branch if lower
|
||||
* if (A = B)
|
||||
L 0,A load R0
|
||||
C 0,B compare
|
||||
BE EQUAL branch if equal
|
||||
* if (A < B)
|
||||
L 0,A load R0
|
||||
C 0,B compare
|
||||
BH GREATER branch if higher
|
||||
* other case ?
|
||||
B RETURN
|
||||
LOWER WTO 'A<B'
|
||||
B RETURN
|
||||
EQUAL WTO 'A=B'
|
||||
B RETURN
|
||||
GREATER WTO 'A>B'
|
||||
B RETURN
|
||||
*
|
||||
RETURN EPILOG
|
||||
A DS F 31-bit signed integer
|
||||
B DS F 31-bit signed integer
|
||||
END
|
||||
5
Task/Integer-comparison/BASIC/integer-comparison-2.basic
Normal file
5
Task/Integer-comparison/BASIC/integer-comparison-2.basic
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
10 INPUT "ENTER TWO INTEGERS: "; A%, B%
|
||||
20 A$(0) = "NOT "
|
||||
30 PRINT A% " IS " A$(A% < B%) "LESS THAN " B%
|
||||
40 PRINT A% " IS " A$(A% = B%) "EQUAL TO " B%
|
||||
50 PRINT A% " IS " A$(A% > B%) "GREATER THAN " B%
|
||||
6
Task/Integer-comparison/Brat/integer-comparison.brat
Normal file
6
Task/Integer-comparison/Brat/integer-comparison.brat
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
first = ask("First integer: ").to_i
|
||||
second = ask("Second integer: ").to_i
|
||||
|
||||
when { first > second } { p "#{first} is greater than #{second}" }
|
||||
{ first < second } { p "#{first} is less than #{second}" }
|
||||
{ first == second } { p "#{first} is equal to #{second}" }
|
||||
1
Task/Integer-comparison/Excel/integer-comparison-1.excel
Normal file
1
Task/Integer-comparison/Excel/integer-comparison-1.excel
Normal file
|
|
@ -0,0 +1 @@
|
|||
=IF($A1>$B1;concatenate($A1;" is greater than ";$B1);IF($A1<$B1;concatenate($A1;" is smaller than ";$B1);concatenate($A1;" is equal to ";$B1)))
|
||||
1
Task/Integer-comparison/Excel/integer-comparison-2.excel
Normal file
1
Task/Integer-comparison/Excel/integer-comparison-2.excel
Normal file
|
|
@ -0,0 +1 @@
|
|||
=IF($A1>$B1,concatenate($A1," is greater than ",$B1),IF($A1<$B1,concatenate($A1," is smaller than ",$B1),concatenate($A1," is equal to ",$B1)))
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
[a,b] = input["Enter numbers",["a","b"]]
|
||||
[a,b] = eval[input["Enter numbers",["a","b"]]]
|
||||
if a<b
|
||||
println["$a < $b"]
|
||||
if a==b
|
||||
|
|
|
|||
|
|
@ -1,36 +1,24 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"bufio"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"fmt"
|
||||
"log"
|
||||
)
|
||||
|
||||
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)
|
||||
}
|
||||
var n1, n2 int
|
||||
if _, err := fmt.Scan(&n1); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if _, err := fmt.Scan(&n2); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
10
Task/Integer-comparison/Julia/integer-comparison.julia
Normal file
10
Task/Integer-comparison/Julia/integer-comparison.julia
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
function compare()
|
||||
int1 = chomp(readline(STDIN))
|
||||
int2 = chomp(readline(STDIN))
|
||||
print(int1, " is ",
|
||||
int1 < int2 ? "less than " :
|
||||
int1 == int2 ? "equal to " :
|
||||
int1 > int2 ? "greater than " :
|
||||
"uncomparable to",
|
||||
int2)
|
||||
end
|
||||
15
Task/Integer-comparison/Rust/integer-comparison.rust
Normal file
15
Task/Integer-comparison/Rust/integer-comparison.rust
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
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 result =
|
||||
match (a, b) {
|
||||
(a, b) if a < b => format!("{0} is less than {1}" , a , b),
|
||||
(a, b) if a == b => format!("{0} equals {1}" , a , b),
|
||||
(a, b) => format!("{0} is greater than {1}" , a , b),
|
||||
};
|
||||
println!("{0}" , result);
|
||||
}
|
||||
|
|
@ -2,7 +2,8 @@ code IntIn=10, Text=12;
|
|||
int A, B;
|
||||
[A:= IntIn(0);
|
||||
B:= IntIn(0);
|
||||
if A<B then Text(0, "A<B^M^J");
|
||||
if A=B then Text(0, "A=B^M^J");
|
||||
if A>B then Text(0, "A>B^M^J");
|
||||
if A<B then Text(0, "A<B");
|
||||
if A=B then Text(0, "A=B");
|
||||
if A>B then Text(0, "A>B");
|
||||
CrLf(0);
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue