Sort three variables: Difference between revisions

add FreeBASIC
(add FreeBASIC)
Line 808:
0
77444</pre>
 
=={{header|FreeBASIC}}==
Shows the use of macros, which are type-agnostic (though you cannot mix string and numerical types).
<lang freebasic>#macro sort_three( x, y, z )
if x>y then swap x, y
if y>z then swap y, z
if x>y then swap x, y
#endmacro
 
'demonstrate this for strings
dim as string x = "lions, tigers, and"
dim as string y = "bears, oh my!"
dim as string z = "(from the ""Wizard of OZ"")"
 
sort_three(x,y,z)
print x
print y
print z : print
 
 
'demonstrate this for signed integers
dim as integer a = 77444
dim as integer b = -12
dim as integer c = 0
 
sort_three(a,b,c)
print a
print b
print c</lang>
{{out}}<pre>(from the "Wizard of OZ")
bears, oh my!
lions, tigers, and
 
-12
0
77444</pre>
 
=={{header|Forth}}==
781

edits