Scrieti o functie in limbaju pascal care va calcula numaru de elemente mai mari ca media aritmetica
Răspunsuri la întrebare
const
maxN = 100;
type
matrice = array [1..maxN] of integer;
procedure zap(var a: matrice; var n: integer);
var
i: integer;
begin
write('n= ');
readln(n);
for i := 1 to n do
begin
write('a[', i, ']=');
readln(a[i]);
end;
end;
function sre(a: matrice; n: integer): real;
var
s, b, i: integer; t: real;
begin
s := 0;
b := 0;
for i := 1 to n do
begin
s := s + a[i];
b := b + 1;
end;
t := s / b;
sre := t;
end;
function nr(a: matrice; n: integer;t:real):integer;
var
d, i: integer;
begin
d := 0;
for i := 1 to n do
if a[i] > t then
begin
d := d + 1;
end;
nr:=d;
end;
var
n,d: integer;
a: matrice;
sr:real;
begin
zap(a, n);
sr:=sre(a, n);
writeln('Media aritmetica = ',sr:0:2);
d := nr(a,n,sr);
writeln('Numar de elemente = ',d);
end.