How to resolve the algorithm Greatest element of a list step by step in the COBOL programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Greatest element of a list step by step in the COBOL programming language

Table of Contents

Problem Statement

Create a function that returns the maximum value in a provided set of values, where the number of values may not be known until run-time.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Greatest element of a list step by step in the COBOL programming language

Source code in the cobol programming language

DISPLAY FUNCTION MAX(nums (ALL))


       IDENTIFICATION DIVISION.
       FUNCTION-ID. greatest-elt.

       DATA DIVISION.
       LOCAL-STORAGE SECTION.
       01  idx                     USAGE INDEX.

       01  Table-Len               CONSTANT 50.

       LINKAGE SECTION.
       01  num-table-area.
           03  num-table           PIC 9(8) OCCURS Table-Len TIMES.

       01  max-elt                 PIC 9(8).

       PROCEDURE DIVISION USING VALUE num-table-area RETURNING max-elt.
           PERFORM VARYING idx FROM 1 BY 1 UNTIL idx > Table-Len
               IF num-table (idx) > max-elt
                   MOVE num-table (idx) TO max-elt
               END-IF
           END-PERFORM

           GOBACK
           .
       END FUNCTION greatest-elt.


  

You may also check:How to resolve the algorithm Binary digits step by step in the 0815 programming language
You may also check:How to resolve the algorithm Sum of squares step by step in the C# programming language
You may also check:How to resolve the algorithm Loops/For with a specified step step by step in the Lambdatalk programming language
You may also check:How to resolve the algorithm Mandelbrot set step by step in the Fōrmulæ programming language
You may also check:How to resolve the algorithm Inheritance/Multiple step by step in the Lasso programming language