Integer comparison: Difference between revisions
m
syntax highlighting fixup automation
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
|||
Line 21:
=={{header|11l}}==
<
V b = Int(input(‘Enter value of b: ’))
Line 29:
print(‘a is greater than b’)
I a == b
print(‘a is equal to b’)</
=={{header|360 Assembly}}==
Input is done by a standard register 1 pointed parameter list.
<
* Reg1=Addr(Addr(argA),Addr(argB))
L 2,0(1) Reg2=Addr(argA)
Line 65:
A DS F 31-bit signed integer
B DS F 31-bit signed integer
END</
=={{header|6502 Assembly}}==
Line 71:
Specific OS/hardware routines for user input and printing are left unimplemented.
It should be noted that this is strictly an unsigned comparison.
<
JSR GetUserInput ;routine not implemented
;integers to compare now in memory locations A and B
Line 85:
A_equals_B: JSR DisplayAEqualsB ;routine not implemented
Done: PLA ;restore Accumulator from stack
RTS ;return from subroutine</
=={{header|68000 Assembly}}==
Line 93:
===Unsigned Comparison===
<
;integers to compare are in D0 and D1
CMP.L D1,D0
Line 118:
Equal:
dc.b "both are equal",0
even</
===Signed Comparison===
<
;integers to compare are in D0 and D1
CMP.L D1,D0
Line 146:
Equal:
dc.b "both are equal",0
even</
=={{header|8051 Assembly}}==
Input/output is specific to hardware; this code assumes the integers are in registers a and b.
There is only one comparison instruction to use: 'not equal'.
<
push psw
cjne a, b, clt
Line 167:
compare_:
pop psw
ret</
Testing for (a <= b) or (a >= b) can be performed by changing the jumps.
=={{header|8th}}==
The user would put the numbers on the stack and then invoke 'compare':
<
: compare \ n m --
2dup n:= if "They are equal" . cr then
2dup n:< if "First less than second" . cr then
n:> if "First greater than second" . cr then ;
</syntaxhighlight>
Alternatively one could use the "n:cmp" word
Line 183:
{{works with|aarch64-linux-gnu-as/qemu-aarch64}}
Compare once (<code>cmp x0, x1</code>) and use conditional branching (<code>b.eq</code> and <code>b.gt</code>).
<
.equ SVC_WRITE, 64
.equ SVC_EXIT, 93
Line 246:
_exit:
mov x8, #SVC_EXIT
svc #0</
=={{header|ABAP}}==
This works in ABAP version 7.40 and above. Note that empty input is evaluated to 0.
<syntaxhighlight lang="abap">
report z_integer_comparison.
Line 265:
write comparison_result.
</syntaxhighlight>
=={{header|Action!}}==
<syntaxhighlight lang=
INT a,b
Line 293:
=={{header|Ada}}==
<
with Ada.Integer_Text_IO; use Ada.Integer_Text_Io;
Line 316:
Put_Line("A is greater than B");
end if;
end Compare_Ints;</
=={{header|Aime}}==
<
output(integer a, integer b, text condition)
{
Line 345:
return 0;
}</
Run as:
<pre>aime FILE integer a 33 integer b 133</pre>
Line 363:
The above distributions of both [[ALGOL 68G]] and [[ELLA ALGOL 68]] compilers only
allow [[wp:ASCII|ASCII]] characters (ASCII has neither "≤", "≥" nor "≠" characters).
<
INT a, b;
read((a, space, b, new line));
Line 383:
print((a," is greater or equal to ", b, new line))
FI
)</
{{out}}
<pre>
Line 392:
=={{header|ALGOL W}}==
<
integer a, b;
Line 405:
if a > b then write( a, " is greater than ", b );
end.</
=={{header|AppleScript}}==
<
set n2 to text returned of (display dialog "Enter the second number:" default answer "") as integer
set msg to {n1}
Line 419:
end if
set end of msg to n2
return msg as string</
Or...
<
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</
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
/* ARM assembly Raspberry PI */
Line 614:
szMessErrDep: .asciz "Too large: overflow 32 bits.\n"
</syntaxhighlight>
=={{header|Arturo}}==
<syntaxhighlight lang="rebol">a: to :integer input "enter a value for a: "
b: to :integer input "enter a value for b: "
Line 625:
=={{header|Astro}}==
<
let b = input('Enter value of b: ')
Line 633:
print 'a is greater than b'
elif a == b:
print 'a is equal to b'</
=={{header|AutoHotkey}}==
Error checking is performed automatically by attaching UpDowns to each of the Edit controls. UpDown controls always yield an in-range number, even when the user has typed something non-numeric or out-of-range in the Edit control.
The default range is 0 to 100.
<
Gui, Add, UpDown, vVar1
Gui, Add, Edit
Line 657:
GuiClose:
ExitApp</
=={{header|Avail}}==
<
a ::= next line from standard input→integer;
b ::= next line from standard input→integer;
If a > b then [Print: "a > b";]
else if a < b then [Print: "a < b";]
else if a = b then [Print: "a = b";];</
=={{header|AWK}}==
<
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
}</
In awk, a double equals symbol is required to test for equality.
A single equals sign is used for assignment, and will cause a bug if it is used within a boolean expression:
<
IF (n=3) PRINT "n is equal to 3" # The incorrectly used equals sign will set n to a value of 3</
=={{header|Axe}}==
<
If r₁<r₂
Disp "LESS THAN",i
Line 691:
Disp "GREATER THAN",i
End
Return</
=={{header|BASIC}}==
==={{header|BaCon}}===
<
INPUT "Enter first number " ,a
INPUT "Enter second number " ,b
IF a < b THEN PRINT a ," is less than ", b
IF a = b THEN PRINT a, " is equal to ", b
IF a > b THEN PRINT a, " is greater than ", b</
{{works with|QuickBasic|4.5}}
<
INPUT "a, b"; a, b 'remember to type the comma when you give the numbers
PRINT "a is ";
Line 711:
IF a = b THEN PRINT "equal to ";
IF a > b THEN PRINT "greater than ";
PRINT "b"</
==={{header|Applesoft BASIC}}===
<
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%</
==={{header|IS-BASIC}}===
<
110 INPUT PROMPT "Enter B: ":B
120 IF A<B THEN
Line 729:
160 ELSE
170 PRINT A;"is greater than ";B
180 END IF</
or
<
110 INPUT PROMPT "Enter B: ":B
120 SELECT CASE A
Line 742:
170 CASE ELSE
180 PRINT A;"is greater than ";B
190 END SELECT</
==={{header|BASIC256}}===
<
input "and a second integer: ", y
if x < y then print x; " is less than "; y
if x = y then print x; " is equal to "; y
if x > y then print x; " is greater than "; y</
==={{header|OxygenBasic}}===
<syntaxhighlight lang="text">
uses console
print "Integer comparison. (press ctrl-c to exit) " cr cr
Line 768:
endif
loop
</syntaxhighlight>
==={{header|QBasic}}===
<
IF x < y THEN PRINT x; " is less than "; y
IF x = y THEN PRINT x; " is equal to "; y
IF x > y THEN PRINT x; " is greater than "; y</
==={{header|True BASIC}}===
<
INPUT x, y
Line 784:
IF x = y THEN PRINT x; " is equal to "; y
IF x > y THEN PRINT x; " is greater than "; y
END</
==={{header|Yabasic}}===
<
if x < y then print x, " is less than ", y : fi
if x = y then print x, " is equal to ", y : fi
if x > y then print x, " is greater than ", y : fi</
==={{Header|Tiny BASIC}}===
<
INPUT A
PRINT "Enter another number"
Line 800:
IF A < B THEN PRINT A," is less than ",B
IF A > B THEN PRINT A," is greater than ",B
IF A = B THEN PRINT A," is equal to ",B</
=={{header|Batch File}}==
<
setlocal EnableDelayedExpansion
set /p a="A: "
Line 813:
) else ( if %a% EQU %b% (
echo %a% is equal to %b%
)))</
{{Out}}
<pre>C:\Test>IntegerComparison.bat
Line 821:
=={{header|BBC BASIC}}==
<
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</
=={{header|bc}}==
{{Works with|GNU bc}}
(POSIX bc doesn't have I/O functions/statements (i.e. <code>read</code> and <code>print</code>) but the rest of the code would work.)
<
b = read()
if (a < b) print "a is smaller than b\n"
if (a > b) print "a is greater than b\n"
if (a == b) print "a is equal to b\n"
quit</
=={{header|Befunge}}==
Line 842:
The branch commands (underline _ and pipe |) test for zero.
<
>&&"=A",,\:."=B ",,,\: .55+,-:0`|
v "<" _v#<
@,+55,," B",,,"A " < "=" <</
=={{header|BQN}}==
The function <code>Comp</code> compares two integers and returns the appropriate string result.
<
⊑(/⟜⟨ "Greater than" "Equal To" "Lesser Than" ⟩>∾=∾<)
Line 858:
"Equal To"
6 Comp 5
"Greater than"</
=={{header|Bracmat}}==
<
& get$:?B
& (!A:!B&out$"A equals B"|)
& (!A:<!B&out$"A is less than B"|)
& (!A:>!B&out$"A is greater than B"|);</
=={{header|Brat}}==
<
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}" }</
=={{header|Burlesque}}==
<
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
Line 885:
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
</syntaxhighlight>
=={{header|C}}==
<
int main()
Line 905:
return 0;
}</
=={{header|C sharp|C#}}==
<
class Program
Line 923:
Console.WriteLine("{0} is greater than {1}", a, b);
}
}</
=={{header|C++}}==
<
int main()
Line 948:
if (a > b)
std::cout << a << " is greater than " << b << "\n";
}</
=={{header|CFEngine}}==
<
bundle agent __main__
{
Line 967:
if => isgreaterthan( "$(first_integer)", "$(second_integer)" );
}
</syntaxhighlight>
=={{header|ChucK}}==
<syntaxhighlight lang="text">
fun void intComparison (int one, int two)
{
Line 979:
// uncomment next line and change values to test
// intComparison (2,4);
</syntaxhighlight>
=={{header|Clean}}==
<
compare a b
Line 993:
(_, a, console) = freadi console
(_, b, console) = freadi console
= compare a b</
=={{header|Clipper}}==
<
IF a < b
? "A is less than B"
Line 1,005:
ENDIF
Return Nil
</syntaxhighlight>
=={{header|Clojure}}==
Line 1,011:
It evaluates the when/println body three times, each time with op and string bound to their corresponding entries in the list of three operator/string pairs.
Note that this does no validation on input: if the user inputs a string then an exception will be thrown.
<
(doseq [[op string] [[< "less than"]
[> "greater than"]
[= "equal to"]]]
(when (op a b)
(println (str a " is " string " " b)))))</
=={{header|CMake}}==
<
# cmake -DA=3 -DB=5 -P compare.cmake
Line 1,037:
if(A GREATER B)
message(STATUS "${A} is greater than ${B}")
endif()</
=={{header|COBOL}}==
{{works with|OpenCOBOL}}
<
PROGRAM-ID. Int-Compare.
Line 1,066:
GOBACK
.</
=={{header|ColdFusion}}==
Line 1,079:
===In CFML===
<
<cfargument name="Integer1" type="numeric">
<cfargument name="Integer2" type="numeric">
Line 1,102:
</cfif>
<cfreturn VARIABLES.Result >
</cffunction></
===In CFScript===
<
function CompareInteger( Integer1, Integer2 ) {
VARIABLES.Result = "";
Line 1,129:
return VARIABLES.Result;
}
</cfscript></
=={{header|Common Lisp}}==
You can type this directly into a REPL:
<
(b (read *standard-input*)))
(cond
Line 1,142:
((> 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)))))</
After hitting enter, the REPL is expecting the two numbers right away.
Line 1,148:
Alternatively, you can wrap this code in a function definition:
<
(let ((a (read *standard-input*))
(b (read *standard-input*)))
Line 1,157:
((> 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)))))</
Then, execute the function for better control:
Line 1,166:
If you run this program, it will halt awaiting user input. Toggle in the value of <math>x</math>, then click <tt>Enter</tt>, then toggle in <math>y</math>, then <tt>Enter</tt>, and then <tt>Run</tt>. <math>x</math> and <math>y</math> must both be unsigned eight-bit integers. The computer will halt with the accumulator storing 1 if <math>x</math>><math>y</math>, 0 if <math>x</math>=<math>y</math>, or -1 if <math>x</math><<math>y</math>; and it will be ready for a fresh pair of integers to be entered.
<
x: NOP
Line 1,193:
JMP start
one: 1</
=={{header|D}}==
<
import std.stdio, std.conv, std.string;
Line 1,213:
if (a > b)
writeln(a, " is greater than ", b);
}</
{{out}}
<pre>10 is less than 20</pre>
=={{header|Dc}}==
<
[Enter two numbers to compare: ]P
? sbsa
Line 1,225:
[ [equal to]]sp lb la =p
la n [ is ]P P [ ]P lbn []pP
</syntaxhighlight>
{{out}}
44 is greater than 3
=={{header|DCL}}==
<
$ inquire b "Please provide another"
$ if a .lt. b then $ write sys$output "the first integer is less"
$ if a .eq. b then $ write sys$output "the integers have the same value"
$ if a .gt. b then $ write sys$output "the first integer is greater"</
{{out}}
<pre>$ @integer_comparison
Line 1,252:
:''Slightly different than the [[#Pascal|Pascal]] example''
<
{$APPTYPE CONSOLE}
Line 1,263:
if a = b then Writeln(a, ' is equal to ', b);
if a > b then Writeln(a, ' is greater than ', b);
end.</
=={{header|Draco}}==
<
int a, b;
write("Please enter two integers: ");
Line 1,274:
elif a>b then writeln(a, " > ", b)
fi
corp</
=={{header|Dyalect}}==
Line 1,280:
{{trans|Clipper}}
<
if a < b {
"A is less than B"
Line 1,288:
"A equals B"
}
}</
=={{header|E}}==
<
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?` })
}</
=={{header|EasyLang}}==
<syntaxhighlight lang="text">a = number input
b = number input
if a < b
Line 1,309:
if a > b
print "greater"
.</
=={{header|ECL}}==
<syntaxhighlight lang="ecl">
CompareThem(INTEGER A,INTEGER B) := FUNCTION
Result := A <=> B;
Line 1,322:
CompareThem(2,2); //Shows "2 is equal to 2"
CompareThem(2,1); //Shows "2 is greater than 1"
</syntaxhighlight>
=={{header|EDSAC order code}}==
The EDSAC offers two conditional branching orders, <tt>E</tt> (branch if the accumulator >= 0) and <tt>G</tt> (branch if the accumulator < 0). Testing for equality thus requires two operations.
<
==================
Line 1,380:
[ 18 ] AF [ - character ]
EZPF [ begin execution ]</
=={{header|Efene}}==
Line 1,386:
since if does pattern matching the else is required to avoid the application from crashing
<
if A == B {
io.format("~p equals ~p~n", [A, B])
Line 1,415:
compare(4, 5)
}
</syntaxhighlight>
=={{header|Eiffel}}==
<
APPLICATION
inherit
Line 1,447:
end
end
end</
=={{header|Elena}}==
ELENA 4.x:
<
public program()
Line 1,466:
if (a > b)
{ console.printLine(a," is greater than ",b) }
}</
=={{header|Elixir}}==
<
{b,_} = IO.gets("Enter your second integer: ") |> Integer.parse
Line 1,479:
a == b ->
IO.puts "#{a} is equal to #{b}"
end</
=={{header|Emacs Lisp}}==
<
"Compare A to B and print the outcome in the message buffer."
(interactive "nFirst integer ⇒\nnSecond integer ⇒")
Line 1,489:
((< a b) (message "%d is less than %d." a b))
((> a b) (message "%d is greater than %d." a b))
((= a b) (message "%d is equal to %d." a b))))</
Invoke from within Emacs Lisp (or e.g., with <code>M-:</code>) as <code>(integer-comparison 12 42)</code>
Line 1,495:
=={{header|Erlang}}==
<
main() ->
{ok, [N]} = io:fread("First integer: ", "~d"),
Line 1,514:
end.
</syntaxhighlight>
=={{header|Euphoria}}==
<
integer a,b
Line 1,531:
puts(1,"grater then")
end if
puts(1," b")</
=={{header|Excel}}==
Line 1,537:
Let's say you type in the values in cells A1 and B1, in C1, type in the following in a MS Excel 2010 sheet:
<
=IF($A1>$B1;concatenate($A1;" is greater than ";$B1);IF($A1<$B1;concatenate($A1;" is smaller than ";$B1);concatenate($A1;" is equal to ";$B1)))
</syntaxhighlight>
In a Google Docs spreadsheet, that becomes :
<
=IF($A1>$B1,concatenate($A1," is greater than ",$B1),IF($A1<$B1,concatenate($A1," is smaller than ",$B1),concatenate($A1," is equal to ",$B1)))
</syntaxhighlight>
=={{header|F_Sharp|F#}}==
<
let r =
match a with
Line 1,555:
| x when x > b -> 1, printfn "%d is greater than %d" x b
| x -> 0, printf "default condition (not reached)"
fst r</
=={{header|Factor}}==
<
readln readln [ string>number ] bi@
[ > [ "A > B" print ] when ]
[ < [ "A < B" print ] when ]
[ = [ "A = B" print ] when ] 2tri ;
</syntaxhighlight>
=={{header|FALSE}}==
Only equals and greater than are available.
<
>[\$," is greater than "\$,]?
\>[\$," is less than "\$,]?
=["characters are equal"]?</
=={{header|Fantom}}==
Line 1,576:
Uses Env.cur to access stdin and stdout.
<
{
public static Void main ()
Line 1,598:
}
}
</syntaxhighlight>
=={{header|Fermat}}==
<syntaxhighlight lang="fermat">Func Compare =
?a;
?b;
Line 1,611:
=={{header|Fish}}==
This example assumes you [http://www.esolangs.org/wiki/Fish#Input.2Foutput pre-populate] the stack with the two integers.
<
v <>l?^"Please pre-populate the stack with the two integers."ar>l?^;
\$:@@:@)?v v ;oanv!!!?<
Line 1,623:
> v
/oo". "nooooo" and "n$< v o<
>"They're not equal, not greater than and not smaller than eachother... strange."ar>l?^;</
The last three lines aren't really needed, because it will never become true :P but I included them to show a way to do some error checking.
Line 1,630:
To keep the example simple, the word takes the two numbers from the stack.
<
2dup < if ." a is less than b" then
2dup > if ." a is greater than b" then
= if ." a is equal to b" then ;</
=={{header|Fortran}}==
In ALL Fortran versions (including original 1950's era) you could use an "arithmetic IF" statement to compare using subtraction:
<
integer a, b
Line 1,653:
40 continue
end</
In ANSI FORTRAN 66 or later you could use relational operators (.lt., .gt., .eq., etc.) and unstructured IF statements:
<
integer a, b
c fortran 77 I/O statements, for simplicity
Line 1,664:
if (a .eq. b) write(*, *) a, ' is equal to ', b
if (a .gt. b) write(*, *) a, ' is greater than ', b
end</
In ANSI FORTRAN 77 or later you can use relational operators and structured IF statements:
<
integer a, b
read(*,*) a, b
Line 1,679:
end if
end</
In ISO Fortran 90 or later you can use symbolic relational operators (<, >, ==, etc.)
<
integer :: a, b
read(*,*) a, b
Line 1,694:
end if
end program compare</
=={{header|FreeBASIC}}==
<
Dim As Integer x, y
Line 1,716:
Print
Print "Press any key to exit"
Sleep</
=={{header|friendly interactive shell}}==
<
read b
Line 1,728:
else if test $a -eq $b
echo Equal
end</
=={{header|Frink}}==
All integers in Frink can be arbitrarily large.
<
if a<b
println["$a < $b"]
Line 1,739:
println["$a == $b"]
if a>b
println["$a > $b"]</
=={{header|FunL}}==
<
a = readInt()
Line 1,749:
val (_, c) = [((<), 'less than'), ((==), 'equal to'), ((>), 'greater than')].find( (compare, _) -> compare(a, b) ).get()
println( "$a is $c $b." )</
=={{header|FutureBasic}}==
Note: Strictly speaking, it's preferable to use "==" when comparing integers as seen in this example. While the "=" sign will work as a comparison in most cases, technically it should be used for assignment, i.e. a = 3 when a is assigned the value of 3, as contrasted with a == 3, where the value of a is being compared with 3. FB will flag a warning when "==" is used to compare two single, doubles or floats since comparing real numbers can be inaccurate.
<
begin enum 1
_integer1Fld
Line 1,801:
on dialog fn DoDialog
HandleEvents</
=={{header|Fōrmulæ}}==
Line 1,812:
=={{header|Gambas}}==
<
Dim sIn As String = InputBox("Enter 2 integers seperated by a comma")
Dim iFirst, iSecond As Integer
Line 1,823:
If iFirst = iSecond Then Print iFirst & " is equal to " & iSecond
End</
Output:
<pre>
Line 1,830:
=={{header|Go}}==
<
import (
Line 1,855:
fmt.Println(n1, "greater than", n2)
}
}</
=={{header|Groovy}}==
===Relational Operators===
<
println "a ? b = ${a} ? ${b} = a ${a < b ? '<' : a > b ? '>' : a == b ? '==' : '?'} b"
}</
Program:
<
comparison(2000,300000)
comparison(2000,2000)</
{{out}}
Line 1,876:
==="Spaceship" (compareTo) Operator===
Using spaceship operator and a lookup table:
<
def comparisonSpaceship = { a, b ->
println "a ? b = ${a} ? ${b} = a ${rels[a <=> b]} b"
}</
Program:
<
comparison(2000,300000)
comparison(2000,2000)</
{{out}}
Line 1,892:
=={{header|Harbour}}==
<
IF a < b
Line 1,902:
ENDIF
RETURN</
=={{header|Haskell}}==
<
myCompare a b
| a < b = "A is less than B"
Line 1,914:
a <- readLn
b <- readLn
putStrLn $ myCompare a b</
However, the more idiomatic and less error-prone way to do it in Haskell would be to use a compare function that returns type Ordering, which is either LT, GT, or EQ:
<
LT -> "A is less than B"
GT -> "A is greater than B"
EQ -> "A equals B"</
=={{header|hexiscript}}==
<
let b scan int
Line 1,935:
if a = b
println a + " is equal to " + b
endif</
=={{header|HicEst}}==
<
IF (a < b) THEN
Line 1,946:
ELSEIF(a > b) THEN
WRITE(Messagebox) a, ' is greater than ', b
ENDIF</
=={{header|HolyC}}==
<
a = Str2I64(GetStr("Enter your first number: "));
b = Str2I64(GetStr("Enter your second number: "));
Line 1,960:
if (a > b)
Print("%d is greater than %d\n", a, b);</
=={{header|Hy}}==
<
(def b (int (input "Enter value of b: ")))
(print (cond [(< a b) "a is less than b"]
[(> a b) "a is greater than b"]
[(= a b) "a is equal to b"]))</
=={{header|i}}==
<
a = number(read(' '))
b = number(read())
Line 1,986:
print(a, " is greater than ", b)
end
}</
=={{header|Icon}} and {{header|Unicon}}==
<
until integer(a) do {
Line 2,004:
write(a," = ", a = b)
write(a," > ", a > b)
end</
{{out}}
Line 2,014:
=={{header|J}}==
Comparison is accomplished by the verb <code>compare</code>, which provides logical-numeric output.<br>Text elaborating the output of <code>compare</code> is provided by <code>cti</code>:
<
cti=: dyad define
Line 2,020:
English =. ' is less than ';' is equal to ';' is greater than '
x (":@[, (compare select English"_), ":@]) y
)</
Examples of use:
<
0 1 0
4 cti 3
4 is greater than 3</
=={{header|Java}}==
<
public class compInt {
Line 2,048:
} catch(IOException e) { }
}
}</
=={{header|JavaScript}}==
<
// Using type coercion
function compare(a, b) {
Line 2,078:
}
}
</syntaxhighlight>
=={{header|Joy}}==
<syntaxhighlight lang=
DEFINE
prompt == "Please enter a number and <Enter>: " putchars;
Line 2,104:
=={{header|jq}}==
<
# otherwise an "uncomparable" message is emitted.
Line 2,119:
end ;
compare</
Examples;
<syntaxhighlight lang="jq">
$ jq -s -r -f Integer_comparison.jq
1 2
Line 2,130:
1 "a"
1 is uncomparable to a
</syntaxhighlight>
=={{header|Julia}}==
<
int1 = readline(stdin)
int2 = readline(stdin)
Line 2,143:
int2)
end
</
<pre>julia> compare()
3
Line 2,151:
=={{header|Kotlin}}==
<
val n1 = readLine()!!.toLong()
val n2 = readLine()!!.toLong()
Line 2,160:
else -> ""
})
}</
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
{def compare
{lambda {:a :b}
Line 2,180:
{compare 1 1}
-> 1 is equal to 1
</syntaxhighlight>
=={{header|Lasso}}==
<
number1 = integer(web_request -> param('number1')),
number2 = integer(web_request -> param('number2'))
Line 2,192:
#number1 == #number2 ? 'Number 1 is the same as Number 2' | 'Number 1 is not the same as Number 2'
'<br />'
#number1 > #number2 ? 'Number 1 is greater than Number 2' | 'Number 1 is not greater than Number 2'</
{{out}}
Line 2,202:
=={{header|Liberty BASIC}}==
Verbose version:
<
input "Enter an integer for b. ";b
Line 2,221:
end select
</
Concise:
<
input "Enter an integer for b. ";b
Line 2,231:
if eval("a"+op$+"b") then print "a"+op$+"b " ; a;" ";op$;" ";b
next
</syntaxhighlight>
=={{header|LIL}}==
<
set rc [readline]
set a [index $rc 0]
Line 2,241:
if {$a < $b} {print "$a is less than $b"}
if {$a == $b} {print "$a is equal to $b"}
if {$a > $b} {print "$a is greater than $b"}</
=={{header|Lingo}}==
Lingo programs are normally not run in the console, so interactive user input is handled via GUI. To not clutter this page with GUI creation code, here only the comparison part of the task:
<
if a < b then put a&" is less than "&b
if a = b then put a&" is equal to "&b
if a > b then put a&" is greater than "&b
end</
=={{header|LiveCode}}==
<
if it is not empty then
put item 1 of it into num1
Line 2,271:
end switch
end if
end if</
=={{header|LLVM}}==
Line 2,278:
{{libheader|cstdlib}}
<
;e means little endian
;p: { pointer size : pointer abi : preferred alignment for pointers }
Line 2,369:
declare i32 @printf(i8* nocapture, ...) nounwind
</syntaxhighlight>
=={{header|Logo}}==
<
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</
Each infix operator has prefix synonyms (equalp, equal?, lessp, less?, greaterp, greater?), where the 'p' stands for "predicate" as in [[Lisp]].
Line 2,383:
==={{header|avec SI}}===
<
ENTIER A, B
LIRE ['Entrez un premier entier:',U] A
Line 2,395:
SI A > B ALORS
AFFICHER [U,' est plus grand que ',U,/] A, B
FIN SI</
==={{header|avec ÉVALUER}}===
<
ENTIER A, B
LIRE ['Entrez un premier entier:',U] A
Line 2,409:
QUAND AUTRE
AFFICHER [U,' est plus grand que ',U,/] A, B
FIN EVALUER</
==={{header|avec SI..IS}}===
<
ENTIER A, B
LIRE ['Entrez un premier entier:',U] A
Line 2,420:
SI A = B ALORS ' est égale à ' SINON \
SI A > B ALORS ' est plus grand que ' SINON '?' IS IS IS, B
</syntaxhighlight>
=={{header|LSE64}}==
<
2dup : over over
Line 2,430:
compare : 2dup > then " is more than"
show : compare rot , sp ,t sp , nl</
=={{header|Lua}}==
<
a = tonumber(io.stdin:read())
print('Enter the second number: ')
Line 2,440:
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</
In lua, a double equals symbol is required to test for equality. A single equals sign is used for assignment, and will cause an error during jit precompilation, if it is used within a boolean expression:
<
=={{header|Maple}}==
<
local a, b;
printf( "Enter a number:> " );
Line 2,462:
end proc:
CompareNumbers();</
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<
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"]]</
=={{header|Maxima}}==
<
block(
[a: read("a?"), b: read("b?")],
Line 2,480:
if a >= b then print(a, ">=", b),
if a = b then print(a, "=", b),
if a # b then print(a, "#", b))$</
=={{header|MAXScript}}==
<
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"</
=={{header|Metafont}}==
<
a1 := scantokens readstring;
message "integer 2: ";
Line 2,501:
message decimal a1 & " is equal to " & decimal a2
fi;
end</
=={{header|min}}==
{{works with|min|0.19.3}}
<
("Enter an integer" ask) 2 times over over
(
Line 2,512:
((==) ("equal to"))
) case
' append prepend % print</
=={{header|MiniScript}}==
<
integer2 = input("Please Input Integer 2:").val
if integer1 < integer2 then print integer1 + " is less than " + integer2
if integer1 == integer2 then print integer1 + " is equal to " + integer2
if integer1 > integer2 then print integer1 + " is greater than " + integer2</
=={{header|МК-61/52}}==
<syntaxhighlight lang="text">- ЗН С/П</
''Input:'' a ^ b
Line 2,532:
Note that ML/I only has tests for ''equality'', ''greater-than'', and ''greater-than-or-equal''.
<
"" assumes macros on input stream 1, terminal on stream 2
MCSKIP MT,<>
Line 2,549:
>
MCSET S1=1
~MCSET S10=2</
=={{header|MMIX}}==
Some simple error checking is included.
<
p IS $255 % pointer
pp GREG % backup for p
Line 2,637:
LDA p,GT % _ : print 'GT'
2H TRAP 0,Fputs,StdOut % print result
TRAP 0,Halt,0</
Example of use:
<pre>~/MIX/MMIX/Progs> mmix compare2ints 121 122
Line 2,658:
=={{header|Modula-2}}==
<
IMPORT InOut;
Line 2,679:
InOut.WriteInt(B, 1);
InOut.WriteLn
END IntCompare.</
=={{header|Modula-3}}==
<
FROM IO IMPORT Put, GetInt;
Line 2,699:
Put(Int(a) & " is greater than " & Int(b) & "\n");
END;
END Main.</
=={{header|MUMPS}}==
<syntaxhighlight lang="text">INTCOMP
NEW A,B
INTCOMPREAD
Line 2,712:
IF A>B WRITE !,A," is greater than ",B
KILL A,B
QUIT</
{{out}}
<pre>USER>d INTCOMP^ROSETTA
Line 2,731:
=={{header|Nanoquery}}==
<
first = int(input())
print "enter second integer: "
Line 2,742:
else if first > second
println first + " is greater than " + second
end</
=={{header|Nemerle}}==
Showing both the use of comparison operators and the .Net Int32.CompareTo() method.
<
using System.Console;
Line 2,776:
}
}
}</
=={{header|NetRexx}}==
<
options replace format comments java crossref symbols nobinary
Line 2,794:
return
</syntaxhighlight>
=={{header|NewLISP}}==
<syntaxhighlight lang="newlisp">
(print "Please enter the first number: ")
(set 'A (int (read-line)))
Line 2,809:
(true "less than"))
" the second.")
</syntaxhighlight>
=={{header|Nim}}==
<
var a = parseInt(readLineFromStdin "Enter value of a: ")
var b = parseInt(readLineFromStdin "Enter value of b: ")
Line 2,821:
echo "a is greater than b"
elif a == b:
echo "a is equal to b"</
=={{header|NSIS}}==
===Pure NSIS (Using [http://nsis.sourceforge.net/Docs/Chapter4.html#4.9.4.13 IntCmp] directly)===
<
Function IntergerComparison
Push $0
Line 2,848:
Pop $0
FunctionEnd
</syntaxhighlight>
=== Using [http://nsis.sourceforge.net/LogicLib LogicLib] (bundled library) ===
{{libheader|LogicLib}}
<
Function IntegerComparison
Push $0
Line 2,870:
Pop $0
FunctionEnd
</syntaxhighlight>
=={{header|Oberon-2}}==
<
IMPORT In, Out;
Line 2,898:
Out.Ln;
END;
END Compare.</
=={{header|Objeck}}==
<
bundle Default {
class IntCompare {
Line 2,922:
}
}
</syntaxhighlight>
=={{header|OCaml}}==
<
if a < b then "A is less than B"
else if a > b then "A is greater than B"
Line 2,934:
let a = read_int ()
and b = read_int () in
print_endline (my_compare a b)</
=={{header|Octave}}==
<
a = scanf("%d", "C");
printf("Enter b: ");
Line 2,947:
elseif (a < b)
disp("a less than b");
endif</
=={{header|Oforth}}==
<
: cmpInt
Line 2,960:
a b < ifTrue: [ System.Out a << " is less than " << b << cr ]
a b == ifTrue: [ System.Out a << " is equal to " << b << cr ]
a b > ifTrue: [ System.Out a << " is greater than " << b << cr ] ;</
=={{header|Ol}}==
<
(define (compare a b)
(cond ((< a b) "A is less than B")
Line 2,980:
; manual user input:
(print (compare (read) (read)))
</syntaxhighlight>
=={{header|Oz}}==
<
import
Application(exit)
Line 3,010:
{Application.exit 0}
end</
=={{header|PARI/GP}}==
<
b=input();
if(a<b, print(a" < "b));
if(a==b, print(a" = "b));
if(a>b, print(a" > "b));</
=={{header|Pascal}}==
<
var
Line 3,033:
if (a = b) then writeln(a, ' is equal to ', b);
if (a > b) then writeln(a, ' is greater than ', b);
end.</
=={{header|Perl}}==
Line 3,040:
Separate tests for less than, greater than, and equals
<
my $f = shift;
my $s = shift;
Line 3,052:
return 0; # returns 0 $f is equal to $s
};
};</
All three tests in one. If $f is less than $s return -1, greater than return 1, equal to return 0
<
return $_[0] <=> $_[1];
};</
Note: In Perl, $a and $b are (kind of) reserved identifiers for the built-in ''sort'' function. It's good style to use more meaningful names, anyway.
<
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";</
=={{header|Phix}}==
{{libheader|Phix/basics}}
<!--<
<span style="color: #004080;">atom</span> <span style="color: #000000;">a</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">prompt_number</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"first number:"</span><span style="color: #0000FF;">,{}),</span>
<span style="color: #000000;">b</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">prompt_number</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"second number:"</span><span style="color: #0000FF;">,{})</span>
Line 3,082:
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" %g"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">b</span><span style="color: #0000FF;">)</span>
<!--</
=={{header|PHL}}==
<
extern printf;
Line 3,106:
return 0;
]</
=={{header|PHP}}==
<
echo "Enter an integer [int1]: ";
Line 3,135:
echo "int1 > int2\n";
?></
Note that this works from the command-line interface only, whereas [http://www.php.net PHP] is usually executed as [[wp:Common_Gateway_Interface CGI]].
=={{header|PicoLisp}}==
<
(in NIL # Read from standard input
Line 3,149:
((= A B) "equal to")
(T "less than") )
" the second." ) ) )</
{{out}}
<pre>Please enter two values: 4 3
Line 3,155:
=={{header|Pike}}==
<
if(argc != 3){
write("usage: `pike compare-two-ints.pike <x> <y>` where x and y are integers.\n");
Line 3,171:
write(a + " is equal to " + b + "\n");
}
}</
=={{header|PL/I}}==
<syntaxhighlight lang="pl/i">
declare (a, b) fixed binary;
Line 3,184:
if a < b then
put skip list ('The second number is greater than the first');
</syntaxhighlight>
=={{header|Plain English}}==
<
Start up.
Write "Enter the first number: " to the console without advancing.
Line 3,197:
If the first number is greater than the second number, write "Greater than!" to the console.
Wait for the escape key.
Shut down.</
=={{header|Pop11}}==
<
define compare_integers(x, y);
if x > y then
Line 3,216:
;;; Read numbers and call comparison procedure
compare_integers(itemrep(), itemrep());</
=={{header|PowerShell}}==
<
$b = [int] (Read-Host b)
Line 3,228:
} elseif ($a -gt $b) {
Write-Host $a is greater than $b`.
}</
=={{header|PureBasic}}==
<
Print("Enter an integer: ")
Line 3,249:
Input()
CloseConsole()
EndIf</
=={{header|Python}}==
<
a = input('Enter value of a: ')
b = input('Enter value of b: ')
Line 3,261:
print 'a is greater than b'
elif a == b:
print 'a is equal to b'</
(Note: in Python3 ''input()'' will become ''int(input())'')
Line 3,268:
{{works with|Python|2.x only, not 3.x}}
<
import sys
try:
Line 3,282:
1: 'is greater than'
}
print a, dispatch[cmp(a,b)], b</
In this case the use of a dispatch table is silly. However, more generally in Python the use of dispatch dictionaries or tables is often preferable to long chains of '''''elif'''' clauses in a condition statement. Python's support of classes and functions (including [[currying]], partial function support, and lambda expressions) as first class objects obviates the need for a "case" or "switch" statement.
Line 3,288:
=={{header|Quackery}}==
<
input quackery cr
say "The first number is "
Line 3,295:
2dup < if [ say "smaller than" ] ]
2drop
say " the second number." cr</
{{out}}
Line 3,317:
=={{header|R}}==
<
a <- scan(what=numeric(0), nmax=1)
print("insert number b")
Line 3,327:
} else if ( a == b ) { # could be simply else of course...
print("a and b are the same")
}</
=={{header|Racket}}==
<
(define (compare-two-ints a b)
(define compared
Line 3,338:
(format "~a ~a ~a" a compared b))
(compare-two-ints (read) (read))</
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku"
my $b = prompt("2nd int: ").floor;
Line 3,353:
elsif $a == $b {
say 'Equal';
}</
With <code><=></code>:
<syntaxhighlight lang="raku"
A three-way comparison such as <tt><=></tt> actually returns an <code>Order</code> enum which stringifies into 'Decrease', 'Increase' or 'Same'. So if it's ok to use this particular vocabulary, you could say that this task is actually a built in:
<syntaxhighlight lang="raku"
=={{header|Rapira}}==
<
input: a
input: b
Line 3,375:
when a = b:
output: "a is equal to b"
esac</
=={{header|Raven}}==
<
expect trim 1.1 prefer as $a
"Enter the second number: " print
Line 3,385:
$a $b < if $b $a "%g is less than %g\n" print
$a $b > if $b $a "%g is greater than %g\n" print
$a $b = if $b $a "%g is equal to %g\n" print</
=={{header|REBOL}}==
<syntaxhighlight lang="rebol">
REBOL [
Title: "Comparing Two Integers"
Line 3,402:
]
print [a "is" case relation b]
</syntaxhighlight>
==={{header|Relation}}===
There is no input, so numbers have to be given in code
<syntaxhighlight lang="relation">
set a = 15
set b = 21
Line 3,418:
end if
end if
</syntaxhighlight>
=={{header|Red}}==
{{trans|REBOL}}
<
Title: "Comparing Two Integers"
URL: http://rosettacode.org/wiki/Comparing_two_integers
Line 3,435:
a > b "greater than"
]
print [a "is" case relation b]</
=={{header|ReScript}}==
<
if a < b { "A is less than B" } else
if a > b { "A is greater than B" } else
Line 3,449:
let b = int_of_string(Sys.argv[3])
Js.log(my_compare(a, b))</
{{out}}
<pre>
Line 3,464:
Taking the numbers from the stack:
<
dup-pair gt? [ 'A>B s:put nl ] if
dup-pair lt? [ 'A<B s:put nl ] if
eq? [ 'A=B s:put nl ] if ;</
=={{header|REXX}}==
<
numeric digits 2000 /*for the users that really go ka─razy.*/
@=copies('─', 20) /*eyeball catcher for the user's eyen. */
Line 3,493:
end /*forever*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
serr: say @ '***error*** ' arg(1); say @ "Please try again."; return</
{{out|output|text= (shows user input and computer program output together):}}
<pre>
Line 3,521:
=={{header|Ring}}==
<
Func Compare a,b
if a < b
Line 3,530:
See "A equals B"
ok
</syntaxhighlight>
=={{header|Rockstar}}==
Line 3,536:
Minimized Rockstar:
<syntaxhighlight lang="rockstar">
(Get two numbers from user)
Listen to Number One
Line 3,551:
If Number One is less than Number Two
Say "The first is less than the second"
</syntaxhighlight>
Idiomatic version:
<syntaxhighlight lang="rockstar">
Listen to your soul
Listen to my words
Line 3,566:
If your soul is smaller than my words,
Say "The second was bigger".
</syntaxhighlight>
=={{header|RPG}}==
Line 3,573:
CALL rc_intcmp (x'00000000' x'00000001')
<syntaxhighlight lang="rpg">
h dftactgrp(*no)
Line 3,596:
dsply message;
*inlr = *on;
</syntaxhighlight>
=={{header|Ruby}}==
This uses Kernel#gets to get input from STDIN, and String#to_i to convert the string into an integer. (Without this conversion, Ruby would compare strings: 5 < 10 but "5" > "10".)
<
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</
Another way:
<
b = (print "enter a value for b: "; gets).to_i
Line 3,617:
when 0; puts "#{a} is equal to #{b}"
when +1; puts "#{a} is greater than #{b}"
end</
Example '''input''' and output:
Line 3,635:
An alternative method, which is similar to the python version mentioned above (at the time of writing this) is:
<
def prompt str
print str, ": "
Line 3,658:
# I hope you can figure this out
puts "#{a} is #{dispatch[a<=>b]} #{b}"</
=={{header|Run BASIC}}==
<
input "2nd number:"; n2
if n1 < n2 then print "1st number ";n1;" is less than 2nd number";n2
if n1 > n2 then print "1st number ";n1;" is greater than 2nd number";n2
if n1 = n2 then print "1st number ";n1;" is equal to 2nd number";n2</
=={{header|Rust}}==
Reading from stdin into a string is cumbersome at the moment, but convenience functions will be implemented in the future.
<
fn main() {
Line 3,688:
println!("{} is greater than {}" , a , b)
};
}</
=={{header|SAS}}==
<
data _null_;
input a b;
Line 3,713:
1 1
;
run;</
=={{header|Scala}}==
<
def main(args: Array[String]): Unit = {
val a=Console.readInt
Line 3,727:
printf("%d is greater than %d\n", a, b)
}
}</
=={{header|Scheme}}==
<
(cond ((< a b) "A is less than B")
((> a b) "A is greater than B")
((= a b) "A equals B")))
(my-compare (read) (read))</
=={{header|Seed7}}==
<
const proc: main is func
Line 3,759:
writeln(a <& " is greater than " <& b);
end if;
end func;</
=={{header|SenseTalk}}==
<
Put It into A
Line 3,781:
If A is Equal to B
Put A& " is Equal to " &B
End If</
=={{header|Sidef}}==
<
var b = read("b: ", Number);
Line 3,795:
elsif (a > b) {
say 'Greater';
}</
{{out}}
<pre>
Line 3,805:
=={{header|Slate}}==
<
( a > b ) ifTrue: [ inform: 'a greater than b\n' ].
Line 3,811:
( a = b ) ifTrue: [ inform: 'a is equal to b\n' ].
] applyTo: {Integer readFrom: (query: 'Enter a: '). Integer readFrom: (query: 'Enter b: ')}.</
=={{header|Smalltalk}}==
<
'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 ].</
=={{header|SNOBOL4}}==
Line 3,826:
Comparisons in Snobol are not operators, but predicate functions that return a null string and generate a success or failure value which allows or blocks statement execution, and which can be tested for branching. Other numeric comparisons are ge (>=), le (<=) and ne (!= ). There is also a parallel set of L-prefixed predicates in modern Snobols for lexical string comparison.
<
output = 'Enter X,Y:'
trim(input) break(',') . x ',' rem . y
Line 3,833:
output = eq(x,y) x ' is equal to ' y :s(end)
output = gt(x,y) x ' is greater than ' y
end</
=={{header|SNUSP}}==
There are no built-in comparison operators, but you can (destructively) check which of two adjacent cells is most positive.
<
> - \# a>b
- <
a<b #\?/</
=={{header|Sparkling}}==
<
if a < b {
print("a < b");
Line 3,852:
} else {
print("either a or b or both are NaN");
}</
=={{header|SQL}}==
{{works with|Oracle}}
<
drop table test;
Line 3,878:
from test
where a > b;
</syntaxhighlight>
<pre>
Line 3,900:
{{works with|Db2 LUW}}
With SQL only:
<
CREATE TABLE TEST (
VAL1 INT,
Line 3,916:
END COMPARISON
FROM TEST;
</syntaxhighlight>
Output:
<pre>
Line 3,948:
{{works with|Db2 LUW}} version 9.7 or higher.
With SQL PL:
<
--#SET TERMINATOR @
Line 3,966:
CALL COMPARISON(2, 2) @
CALL COMPARISON(2, 1) @
</syntaxhighlight>
Output:
<pre>
Line 4,018:
halt</pre>
To run the SSEM program, load A into storage address 21 and B into storage address 22. No additional space is used. Like the pseudocode version, the program halts with the accumulator holding 1 if A>B, 0 if A=B, or -1 if A<B.
<
10101000000001100000000000000000 1. c to 21
10101000000000100000000000000000 2. -21 to c
Line 4,038:
11111111111111111111111111111111 18. -1
11010000000000000000000000000000 19. 11
10110000000000000000000000000000 20. 13</
=={{header|Standard ML}}==
<
if a < b then print "A is less than B\n"
if a > b then print "A is greater than B\n"
Line 4,054:
compare_integers (a, b)
end
handle Bind => print "Invalid number entered!\n"</
A more idiomatic and less error-prone way to do it in SML would be to use a compare function that returns type <tt>order</tt>, which is either LESS, GREATER, or EQUAL:
<
LESS => "A is less than B"
| GREATER => "A is greater than B"
| EQUAL => "A equals B"</
=={{header|Swift}}==
<
var input = NSFileHandle.fileHandleWithStandardInput()
Line 4,078:
if (a==b) {println("\(a) equals \(b)")}
if (a < b) {println("\(a) is less than \(b)")}
if (a > b) {println("\(a) is greater than \(b)")}</
{{out}}
<pre>
Line 4,089:
This is not how one would write this in Tcl, but for the sake of clarity:
<
gets stdin x
Line 4,096:
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" }</
Other comparison operators are "<=", ">=" and "!=".
Line 4,102:
Note that Tcl doesn't really have a notion of a variable "type" - all variables are just strings of bytes and notions like "integer" only ever enter at interpretation time. Thus the above code will work correctly for "5" and "6", but "5" and "5.5" will also be compared correctly. It will not be an error to enter "hello" for one of the numbers ("hello" is greater than any integer). If this is a problem, the type can be expressly cast
<
or otherwise [[IsNumeric | type can be checked]] with "<tt>if { string is integer $x }...</tt>"
Line 4,109:
A variant that iterates over comparison operators, demonstrated in an interactive [[tclsh]]:
<
% foreach {o s} {< "less than" > "greater than" == equal} {if [list $i $o $j] {puts "$i is $s $j"}}
5 is less than 6
Line 4,117:
% 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</
=={{header|TI-83 BASIC}}==
<
If A<B: Disp "A SMALLER B"
If A>B: Disp "A GREATER B"
If A=B: Disp "A EQUAL B"</
=={{header|TI-89 BASIC}}==
<
Prompt a, b
If a < b Then
Line 4,138:
"???" → result
EndIf
Disp string(a) & " " & result & " " & string(b)</
=={{header|Toka}}==
<
2dup < [ ." a is less than b\n" ] ifTrue
2dup > [ ." a is greater than b\n" ] ifTrue
Line 4,149:
1 1 compare-integers
2 1 compare-integers
1 2 compare-integers</
=={{header|TUSCRIPT}}==
<
$$ MODE TUSCRIPT
Line 4,163:
IF (i1<i2) PRINT i1," is less than ",i2
IF (i1>i2) PRINT i1," is greater than ",i2
</syntaxhighlight>
=={{header|UNIX Shell}}==
Line 4,170:
{{works with|ksh93}}
<
# tested with ksh93s+
Line 4,191:
fi
exit 0</
One can backport the previous code to pdksh, which has no builtin printf, but can call /usr/bin/printf as an external program.
Line 4,197:
{{works with|pdksh}}
<
# tested with pdksh
Line 4,216:
fi
exit 0</
----
Line 4,222:
{{works with|Bash}}
<
if [ $a -gt $b ]; then comparison="greater than"
Line 4,230:
fi
echo "${a} is ${comparison} ${b}"</
=={{header|Ursa}}==
<
out "enter first integer: " console
set first (in int console)
Line 4,247:
if (> first second)
out first " is greater than " second endl console
end if</
=={{header|V}}==
<
[ [>] ['less than' puts]
[<] ['greater than' puts]
Line 4,261:
less than
|2 2 compare
is equal</
=={{header|Vala}}==
<
void main(){
int a;
Line 4,282:
stdout.printf("%d is greater than %d\n", a, b);
}
</syntaxhighlight>
=={{header|VBA}}==
<
first_integer = CInt(InputBox("Give me an integer."))
second_integer = CInt(InputBox("Give me another integer."))
Line 4,291:
Debug.Print IIf(first_integer = second_integer, "first integer is equal to second integer", "first integer is not equal to second integer")
Debug.Print IIf(first_integer > second_integer, "first integer is bigger than second integer", "first integer is not bigger than second integer")
End Sub</
=={{header|VBScript}}==
Based on the BASIC
=====Implementation=====
<syntaxhighlight lang="vb">
option explicit
Line 4,324:
eef( a = b, "equal to ", _
eef( a > b, "greater than ", vbnullstring ) ) ) & "Second integer."
</syntaxhighlight>
=={{header|Visual Basic .NET}}==
Line 4,330:
{{works with|Visual Basic .NET|9.0+}}
<
Dim a = CInt(Console.ReadLine)
Line 4,350:
End Select
End Sub</
=={{header|Wart}}==
<
b <- (read)
prn (if (a < b)
Line 4,360:
: "a is greater than b"
:else
: "a equals b")</
=={{header|Wren}}==
<
System.print("Enter anything other than a number to quit at any time.\n")
Line 4,384:
}
System.print()
}</
{{out}}
Line 4,407:
=={{header|XLISP}}==
<
(DISPLAY "Enter two integers separated by a space.")
(NEWLINE)
Line 4,416:
((> A B) (DISPLAY "The first number is larger."))
((= A B) (DISPLAY "They are equal."))
((< A B) (DISPLAY "The first number is smaller."))))</
=={{header|XPL0}}==
<
int A, B;
[A:= IntIn(0);
Line 4,427:
if A>B then Text(0, "A>B");
CrLf(0);
]</
=={{header|XSLT}}==
Because XSLT uses XML syntax, the less than and greater than operators which would normally be written '<' and '>' must be escaped using character entities, even inside of XPath expressions.
<
<xsl:param name="a" select="1"/>
<xsl:param name="b" select="2"/>
Line 4,442:
</xsl:choose>
</fo:block>
</xsl:template></
=={{header|zkl}}==
<
(if (x==y) "equal" else if (x<y) "less" else if(x>y) "greater").println()</
{{out}}
<pre>
Line 4,454:
=={{header|ZX Spectrum Basic}}==
<
20 PRINT a;" is ";("less than " AND (a<b));("equal to " AND (a=b));("greather than " AND (a>b));b</
|