Integer comparison: Difference between revisions
Dialects of BASIC moved to the BASIC section.
m (→{{Header|Tiny BASIC}}: Works with (Tom Pittman's) TinyBasic.) |
(Dialects of BASIC moved to the BASIC section.) |
||
Line 694:
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
<syntaxhighlight lang="applesoftbasic">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%</syntaxhighlight>
==={{header|BaCon}}===
Line 702 ⟶ 708:
IF a = b THEN PRINT a, " is equal to ", b
IF a > b THEN PRINT a, " is greater than ", b</syntaxhighlight>
{{works with|QuickBasic|4.5}}
Line 713 ⟶ 718:
PRINT "b"</syntaxhighlight>
==={{header|
<syntaxhighlight lang="
input "and a second integer: ", y
==={{header|BBC BASIC}}===
<syntaxhighlight lang="bbcbasic"> 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</syntaxhighlight>
==={{header|FreeBASIC}}===
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64
Dim As Integer x, y
Input "Please enter two integers, separated by a comma : ", x , y
If x < y Then
Print x; " is less than "; y
End If
If x = y Then
Print x; " is equal to "; y
End If
If x > y Then
Print x; " is greater than "; y
End If
Print
Print "Press any key to exit"
Sleep</syntaxhighlight>
==={{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.
<syntaxhighlight lang="futurebasic">_window = 1
begin enum 1
_integer1Fld
_integer2Fld
_compareBtn
_messageLabel
end enum
local fn BuildWindow
window _window, @"Integer Comparison", (0,0,356,85)
textfield _integer1Fld,,, (20,44,112,21)
TextFieldSetPlaceholderString( _integer1Fld, @"Integer 1" )
textfield _integer2Fld,,, (140,44,112,21)
TextFieldSetPlaceholderString( _integer2Fld, @"Integer 2" )
button _compareBtn,,, @"Compare", (253,38,90,32)
textlabel _messageLabel,, (18,20,320,16)
ControlSetAlignment( _messageLabel, NSTextAlignmentCenter )
end fn
local fn DoDialog( ev as long, tag as long )
long int1, int2
select ( ev )
case _btnClick
select ( tag )
case _compareBtn
int1 = fn ControlIntegerValue( _integer1Fld )
int2 = fn ControlIntegerValue( _integer2Fld )
if ( int1 < int2 ) then textlabel _messageLabel, @"The first integer is less than the second integer."
if ( int1 == int2 ) then textlabel _messageLabel, @"The first integer is equal to the second integer."
if ( int1 > int2 ) then textlabel _messageLabel, @"The first integer is greater than the second integer."
end select
case _controlTextDidChange
textlabel _messageLabel, @""
end select
end fn
fn BuildWindow
on dialog fn DoDialog
HandleEvents</syntaxhighlight>
==={{header|Gambas}}===
<syntaxhighlight lang="gambas">Public Sub Form_Open()
Dim sIn As String = InputBox("Enter 2 integers seperated by a comma")
Dim iFirst, iSecond As Integer
iFirst = Val(Split(sIn)[0])
iSecond = Val(Split(sIn)[1])
If iFirst < iSecond Then Print iFirst & " is smaller than " & iSecond & gb.NewLine
If iFirst > iSecond Then Print iFirst & " is greater than " & iSecond & gb.NewLine
If iFirst = iSecond Then Print iFirst & " is equal to " & iSecond
End</syntaxhighlight>
Output:
<pre>
21 is greater than 18
</pre>
==={{header|IS-BASIC}}===
Line 744 ⟶ 849:
190 END SELECT</syntaxhighlight>
==={{header|
Verbose version:
{{works with|Just BASIC}}
<syntaxhighlight lang="lb">input "Enter an integer for a. ";a
input "Enter an integer for b. ";b
'a=int(a):b=int(b) ???
print "Conditional evaluation."
if
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
</syntaxhighlight>
Concise:
<syntaxhighlight lang="lb">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
</syntaxhighlight>
==={{header|OxygenBasic}}===
Line 769 ⟶ 899:
loop
</syntaxhighlight>
==={{header|PureBasic}}===
<syntaxhighlight lang="purebasic">If OpenConsole()
Print("Enter an integer: ")
x.i = Val(Input())
Print("Enter another integer: ")
y.i = Val(Input())
If x < y
Print( "The first integer is less than the second integer.")
ElseIf x = y
Print("The first integer is equal to the second integer.")
ElseIf x > y
Print("The first integer is greater than the second integer.")
EndIf
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit")
Input()
CloseConsole()
EndIf</syntaxhighlight>
==={{header|QBasic}}===
Line 777 ⟶ 928:
IF x > y THEN PRINT x; " is greater than "; y</syntaxhighlight>
==={{header|
<syntaxhighlight lang="
input "2nd number:"; n2
if n1 = n2 then print "1st number ";n1;" is equal to 2nd number";n2</syntaxhighlight>
==={{header|
<syntaxhighlight lang="
If A<B: Disp "A SMALLER B"
If A>B: Disp "A GREATER B"
If A=B: Disp "A EQUAL B"</syntaxhighlight>
==={{header|TI-89 BASIC}}===
<syntaxhighlight lang="ti89b">Local a, b, result
Prompt a, b
If a < b Then
"<" → result
ElseIf a = b Then
"=" → result
ElseIf a > b Then
">" → result
Else
"???" → result
EndIf
Disp string(a) & " " & result & " " & string(b)</syntaxhighlight>
==={{Header|Tiny BASIC}}===
Line 805 ⟶ 968:
80 IF A = B THEN PRINT A;" is equal to ";B
90 END</syntaxhighlight>
==={{header|True BASIC}}===
<syntaxhighlight lang="qbasic">PRINT "Please enter two integers, separated by a comma: ";
INPUT x, 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
END</syntaxhighlight>
==={{header|VBA}}===
<syntaxhighlight lang="vb">Public Sub integer_comparison()
first_integer = CInt(InputBox("Give me an integer."))
second_integer = CInt(InputBox("Give me another integer."))
Debug.Print IIf(first_integer < second_integer, "first integer is smaller than second integer", "first integer is not smaller than second integer")
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</syntaxhighlight>
==={{header|VBScript}}===
<syntaxhighlight lang="vb">
option explicit
function eef( b, r1, r2 )
if b then
eef = r1
else
eef = r2
end if
end function
dim a, b
wscript.stdout.write "First integer: "
a = cint(wscript.stdin.readline) 'force to integer
wscript.stdout.write "Second integer: "
b = cint(wscript.stdin.readline) 'force to integer
wscript.stdout.write "First integer is "
if a < b then wscript.stdout.write "less than "
if a = b then wscript.stdout.write "equal to "
if a > b then wscript.stdout.write "greater than "
wscript.echo "Second integer."
wscript.stdout.write "First integer is " & _
eef( a < b, "less than ", _
eef( a = b, "equal to ", _
eef( a > b, "greater than ", vbnullstring ) ) ) & "Second integer."
</syntaxhighlight>
==={{header|Visual Basic .NET}}===
'''Platform:''' [[.NET]]
{{works with|Visual Basic .NET|9.0+}}
<syntaxhighlight lang="vbnet">Sub Main()
Dim a = CInt(Console.ReadLine)
Dim b = CInt(Console.ReadLine)
'Using if statements
If a < b Then Console.WriteLine("a is less than b")
If a = b Then Console.WriteLine("a equals b")
If a > b Then Console.WriteLine("a is greater than b")
'Using Case
Select Case a
Case Is < b
Console.WriteLine("a is less than b")
Case b
Console.WriteLine("a equals b")
Case Is > b
Console.WriteLine("a is greater than b")
End Select
End Sub</syntaxhighlight>
==={{header|Yabasic}}===
<syntaxhighlight lang="yabasic">input "Please enter two integers, separated by a comma: " x, y
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</syntaxhighlight>
==={{header|ZX Spectrum Basic}}===
<syntaxhighlight lang="zxbasic">10 INPUT "Enter two integers: ";a;" ";b
20 PRINT a;" is ";("less than " AND (a<b));("equal to " AND (a=b));("greather than " AND (a>b));b</syntaxhighlight>
=={{header|Batch File}}==
Line 823 ⟶ 1,072:
B: 3
5 is greater than 3</pre>
=={{header|bc}}==
Line 1,715 ⟶ 1,956:
end program compare</syntaxhighlight>
=={{header|friendly interactive shell}}==
Line 1,770 ⟶ 1,989:
println( "$a is $c $b." )</syntaxhighlight>
=={{header|Fōrmulæ}}==
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation —i.e. XML, JSON— they are intended for storage and transfer purposes more than visualization and edition.
Line 1,830 ⟶ 1,996:
In '''[https://formulae.org/?example=Integer_comparison this]''' page you can see the program(s) related to this task and their results.
=={{header|Go}}==
Line 2,236 ⟶ 2,384:
Number 1 is the same as Number 2
Number 1 is not greater than Number 2</pre>
=={{header|LIL}}==
Line 3,285 ⟶ 3,400:
Write-Host $a is greater than $b`.
}</syntaxhighlight>
=={{header|Python}}==
Line 3,729 ⟶ 3,823:
# I hope you can figure this out
puts "#{a} is #{dispatch[a<=>b]} #{b}"</syntaxhighlight>
=={{header|Rust}}==
Line 4,188 ⟶ 4,274:
% foreach {o s} {< "less than" > "greater than" == equal} {if [list $i $o $j] {puts "$i is $s $j"}}
5 is greater than 4</syntaxhighlight>
=={{header|Toka}}==
Line 4,353 ⟶ 4,418:
}
</syntaxhighlight>
=={{header|Wart}}==
Line 4,522 ⟶ 4,519:
greater
</pre>
|