Compute The Mean Example Program


Click below to go directly to a specific section:
Description | Source Code | Program Notes

Description

This program computes the mean (average) of the absolute value of an array. Block structures, a dynamic array, and iterative statements are featured in this program. The bold type print represent keywords.

Source Code


// the main program (this is a comment)

begin
  integer N;
  Read Int(N);

  begin
    real array Data[1:N];
    real sum, avg;
    integer i;
    sum:=0;

    for i:=1 step 1 until N do
      begin real val;
        Read Real(val);
        Data[i]:=if val<0 then -val else val
      end;

    for i:=1 step 1 until N do
      sum:=sum + Data[i];
    avg:=sum/N;
    Print Real(avg)
  end
end	


Program Notes

This program has NOT been tested due to the inability to locate the necessary compiler. It is posted here just to give you an example of what ALGOL source code looks like. Compare it to the other example listed to see the syntactic differences that exist in the language.
[Back] [Home]

Last modified: 08:52 PM on 11/21/1996