Sort three variables: Difference between revisions

Content added Content deleted
m (→‎{{header|Phix}}: reformat)
(Add Cowgol)
Line 591: Line 591:
y = 0
y = 0
z = 77444</pre>
z = 77444</pre>

=={{header|Cowgol}}==

<lang cowgol>include "cowgol.coh";

# Sort 3 values
sub sort3(a: int32, b: int32, c: int32): (x: int32, y: int32, z: int32) is
sub sort2(a: int32, b: int32): (x: int32, y: int32) is
if a > b then
x := b;
y := a;
else
x := a;
y := b;
end if;
end sub;
x := a;
y := b;
z := c;
(x, y) := sort2(x, y);
(x, z) := sort2(x, z);
(y, z) := sort2(y, z);
end sub;

# Print 3 values
sub print3(a: int32, b: int32, c: int32) is
sub print1(a: int32) is
var buf: uint8[10];
[IToA(a, 10, &buf[0])] := 0;
print(&buf[0]);
print_char(' ');
end sub;
print1(a);
print1(b);
print1(c);
print_nl();
end sub;
var x: int32 := 77444;
var y: int32 := -12;
var z: int32 := 0;

# Print 3 values before sorting
print3(x, y, z);

# Sort 3 values
(x, y, z) := sort3(x, y, z);

# Print 3 values after sorting
print3(x, y, z);</lang>

{{out}}

<pre>77444 -12 0
-12 0 77444</pre>


=={{header|D}}==
=={{header|D}}==