In a four-digit number, first determine the largest digit and output it, then the smallest digit and output it, then find the difference
In a four-digit number, first determine the largest digit and output it, then the smallest digit and output it, then find the difference between the larger and smaller digit.
var
a, b, c, d: char;
ai, bi, ci, di: integer;
function min (x, y: integer): integer; // function that finds at least 2 numbers
begin
if (x <y) then min: = x
else min: = y;
end;
function max (x, y: integer): integer; // function that finds the maximum of 2 numbers
begin
if (x> y) then max: = x
else max: = y;
end;
begin
read (a, b, c, d);
ai: = strtoint (a);
bi: = strtoint (b);
ci: = strtoint (c);
di: = strtoint (d);
writeln (min (min (ai, bi), min (ci, di))); // display the minimum
writeln (max (max (ai, bi), max (ci, di))); // display the maximum
writeln (max (max (ai, bi), max (ci, di)) – min (min (ai, bi), min (ci, di))); // displaying the difference between the maximum and minimum
end.