Program n1; Uses CRT; Var s,k,i: integer; sr: real; begin Writeln('Vvodite chisla. Vvedite 0 dlya okoncania vvoda'); Repeat Readln(i); s:=s+i; inc(k); Until i=0; sr:=s/(k-1); Writeln('Srednee arifmeticheskoe = ',sr:4:4); readln end.
2) С цикла While
Program n1; Uses CRT; Var s,k,i: integer; sr: real; begin Writeln('Vvodite chisla. Vvedite 0 dlya okoncania vvoda'); i:=1; While i<>0 do begin Readln(i); s:=s+i; inc(k); end; sr:=s/(k-1); Writeln('Srednee arifmeticheskoe = ',sr:4:4); readln end.
3) С цикла For
Program n1; Uses CRT; Var s,j,k,i: integer; sr: real; begin Writeln('Vvedite kolichestvo chisel'); Readln(k); Writeln('Vvodite chisla'); For j:=1 to k do begin readln(i); s:=s+i; end; sr:=s/k; writeln('Srednee arifmeticheskoe = ',sr:4:4); readln end.
Предполагается, что вводимые числа - целые.
1) С цикла Repeat Until
Program n1;
Uses CRT;
Var s,k,i: integer;
sr: real;
begin
Writeln('Vvodite chisla. Vvedite 0 dlya okoncania vvoda');
Repeat
Readln(i);
s:=s+i;
inc(k);
Until i=0;
sr:=s/(k-1);
Writeln('Srednee arifmeticheskoe = ',sr:4:4);
readln
end.
2) С цикла While
Program n1;
Uses CRT;
Var s,k,i: integer;
sr: real;
begin
Writeln('Vvodite chisla. Vvedite 0 dlya okoncania vvoda');
i:=1;
While i<>0 do
begin
Readln(i);
s:=s+i;
inc(k);
end;
sr:=s/(k-1);
Writeln('Srednee arifmeticheskoe = ',sr:4:4);
readln
end.
3) С цикла For
Program n1;
Uses CRT;
Var s,j,k,i: integer;
sr: real;
begin
Writeln('Vvedite kolichestvo chisel');
Readln(k);
Writeln('Vvodite chisla');
For j:=1 to k do
begin
readln(i);
s:=s+i;
end;
sr:=s/k;
writeln('Srednee arifmeticheskoe = ',sr:4:4);
readln
end.