How to resolve the algorithm Sort three variables step by step in the COBOL programming language
How to resolve the algorithm Sort three variables step by step in the COBOL programming language
Table of Contents
Problem Statement
Sort (the values of) three variables (X, Y, and Z) that contain any value (numbers and/or literals). If that isn't possible in your language, then just sort numbers (and note if they can be floating point, integer, or other). I.E.: (for the three variables x, y, and z), where: After sorting, the three variables would hold: For numeric value sorting, use: I.E.: (for the three variables x, y, and z), where: After sorting, the three variables would hold: The variables should contain some form of a number, but specify if the algorithm used can be for floating point or integers. Note any limitations. The values may or may not be unique. The method used for sorting can be any algorithm; the goal is to use the most idiomatic in the computer programming language used. More than one algorithm could be shown if one isn't clearly the better choice.
One algorithm could be:
Another algorithm (only for numeric values):
Show the results of the sort here on this page using at least the values of those shown above.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Sort three variables step by step in the COBOL programming language
Source code in the cobol programming language
program-id. 3var.
data division.
working-storage section.
1 n binary pic 9(4).
1 num pic -(7)9.
1 a1 pic x(32) value "lions, tigers, and".
1 a2 pic x(32) value "bears, oh my!".
1 a3 pic x(32) value "(from the ""Wizard of OZ"")".
1 n1 pic x(8) value "77444".
1 n2 pic x(8) value "-12".
1 n3 pic x(8) value "0".
1 alpha-table.
2 alpha-entry occurs 3 pic x(32).
1 numeric-table.
2 numeric-entry occurs 3 pic s9(8).
1 filler value "x = y = z = ".
2 lead-in occurs 3 pic x(4).
procedure division.
begin.
move a1 to alpha-entry (1)
move a2 to alpha-entry (2)
move a3 to alpha-entry (3)
sort alpha-entry ascending alpha-entry
perform varying n from 1 by 1
until n > 3
display lead-in (n) alpha-entry (n)
end-perform
display space
compute numeric-entry (1) = function numval (n1)
compute numeric-entry (2) = function numval (n2)
compute numeric-entry (3) = function numval (n3)
sort numeric-entry ascending numeric-entry
perform varying n from 1 by 1
until n > 3
move numeric-entry (n) to num
display lead-in (n) num
end-perform
stop run
.
end program 3var.
You may also check:How to resolve the algorithm Boolean values step by step in the Maxima programming language
You may also check:How to resolve the algorithm Brownian tree step by step in the Processing programming language
You may also check:How to resolve the algorithm Check output device is a terminal step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Bitwise IO step by step in the MIPS Assembly programming language
You may also check:How to resolve the algorithm Loops/Wrong ranges step by step in the Perl programming language