How to resolve the algorithm Averages/Mode step by step in the PL/I programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Averages/Mode step by step in the PL/I programming language

Table of Contents

Problem Statement

Write a program to find the mode value of a collection. The case where the collection is empty may be ignored. Care must be taken to handle the case where the mode is non-unique. If it is not appropriate or possible to support a general collection, use a vector (array), if possible. If it is not appropriate or possible to support an unspecified value type, use integers.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Averages/Mode step by step in the PL/I programming language

Source code in the pl/i programming language

av: procedure options (main);  /* 28 October 2013 */
   declare x(10) fixed binary static initial (1, 4, 2, 6, 2, 5, 6, 2, 4, 2);
   declare f(32767) fixed binary;
   declare (j, n, max, value) fixed binary;
   declare i fixed;

   n = hbound(x,1);

   do i = 1 to n;
      j = x(i);
      f(j) = f(j) + 1;
   end;
   max = 0;
   do i = 1 to hbound(f,1);
      if max < f(i) then do; max = f(i); value = i; end;
   end;
   put list ('The mode value is ' || value || ' occurred ' ||
             max || ' times.');

end av;

  

You may also check:How to resolve the algorithm Partition an integer x into n primes step by step in the J programming language
You may also check:How to resolve the algorithm Pinstripe/Printer step by step in the Nim programming language
You may also check:How to resolve the algorithm Write language name in 3D ASCII step by step in the Java programming language
You may also check:How to resolve the algorithm Mouse position step by step in the Octave programming language
You may also check:How to resolve the algorithm Greatest subsequential sum step by step in the PHP programming language