program AverageCalculation; var arr: array of Integer; N, i, sum: Integer; average: Real; begin Write('Enter the number of elements in the array: '); Readln(N); SetLength(arr, N); sum := 0; for i := 0 to N - 1 do begin Write('Enter element ', i + 1, ': '); Readln(arr[i]); sum := sum + arr[i]; end; average := sum / N; Writeln('Average: ', average:0:2); end.
Пример работы программы:
Enter the number of elements in the array: 5 Enter element 1: 10 Enter element 2: 20 Enter element 3: 30 Enter element 4: 40 Enter element 5: 50 Average: 30.00
var
arr: array of Integer;
N, i, sum: Integer;
average: Real;
begin
Write('Enter the number of elements in the array: ');
Readln(N);
SetLength(arr, N);
sum := 0;
for i := 0 to N - 1 do
begin
Write('Enter element ', i + 1, ': ');
Readln(arr[i]);
sum := sum + arr[i];
end;
average := sum / N;
Writeln('Average: ', average:0:2);
end.
Пример работы программы:
Enter the number of elements in the array: 5Enter element 1: 10
Enter element 2: 20
Enter element 3: 30
Enter element 4: 40
Enter element 5: 50
Average: 30.00