Write an Pascal Program For Calculating Average of An Array by Passing Arrays as Subprogram Arguments - Computer Programming

Latest

C C++ Java Python Perl Programs Examples with Output -useful for Schools & College Students

Saturday, September 23, 2017

Write an Pascal Program For Calculating Average of An Array by Passing Arrays as Subprogram Arguments

Average Of An Array By  Passing Arrays as Subprogram Arguments

Program:
program arrayToFunction;
const
size = 5;
type
a = array [1..size] of integer;
var
balance:  a = (1000, 2, 3, 17, 50);
average: real;

function avg( var arr: a) : real;
var
i :1..size;
sum: integer;

begin
sum := 0;
for i := 1 to size do
sum := sum + arr[i];
avg := sum / size;
end;

begin
(*  Passing the array to the function  *)
average := avg( balance ) ;

(* output the returned value *)
writeln( 'Average value is: ', average:7:2);
end.

Output:

Average value is: 214.40

No comments:

Post a Comment