Program Massive;
uses Crt;
const
M = 6;
var
D: array [1..M] of real;
i: integer;
sum: real;
indexMax: integer;
begin
ClrScr;
Randomize;
writeln ('Massive:');
indexMax := 1;
D[1] := 10;
D[1] := D[1] - Random(20);
writeln (D[1]);
for i:= 2 to M do
D[i] := 10.0;
D[i] := D[i] - Random(20);
writeln (D[i]);
if (D[i] > D[indexMax]) then
indexMax := i;
end;
writeln ('indexMax = ', indexMax);
sum := 0;
for i:= indexMax + 1 to M do
if (D[i] < 0) then sum := sum + D[i];
writeln ('Sum = ', sum);
readln
end.
const n=10;
var a:array [1..n] of real;
i,j,k:integer;
s,v:real;
write(' Исходный массив: ');
for i:=1 to n do
a[i]:=random*20-10;
write(a[i]:7:2);
if a[i]<0 then
s:=s+a[i]*a[i];
k:=k+1
if a[i]>0 then a[i]:=i
writeln;
write('Преобразованый массив: ');
for i:=1 to n do write(a[i]:7:2);
for j:=1 to n-i do
if a[j]>a[j+1] then
v:=a[j];
a[j]:=a[j+1];
a[j+1]:=v
write('Отсортированый массив: ');
writeln('Среднее арифметическое квадратов отрицательных чисел равно ',s/k:0:2);
Program Massive;
uses Crt;
const
M = 6;
var
D: array [1..M] of real;
i: integer;
sum: real;
indexMax: integer;
begin
ClrScr;
Randomize;
writeln ('Massive:');
indexMax := 1;
D[1] := 10;
D[1] := D[1] - Random(20);
writeln (D[1]);
for i:= 2 to M do
begin
D[i] := 10.0;
D[i] := D[i] - Random(20);
writeln (D[i]);
if (D[i] > D[indexMax]) then
begin
indexMax := i;
end;
end;
writeln ('indexMax = ', indexMax);
sum := 0;
for i:= indexMax + 1 to M do
if (D[i] < 0) then sum := sum + D[i];
writeln ('Sum = ', sum);
readln
end.
const n=10;
var a:array [1..n] of real;
i,j,k:integer;
s,v:real;
begin
write(' Исходный массив: ');
for i:=1 to n do
begin
a[i]:=random*20-10;
write(a[i]:7:2);
if a[i]<0 then
begin
s:=s+a[i]*a[i];
k:=k+1
end;
if a[i]>0 then a[i]:=i
end;
writeln;
write('Преобразованый массив: ');
for i:=1 to n do write(a[i]:7:2);
writeln;
for i:=1 to n do
for j:=1 to n-i do
if a[j]>a[j+1] then
begin
v:=a[j];
a[j]:=a[j+1];
a[j+1]:=v
end;
write('Отсортированый массив: ');
for i:=1 to n do write(a[i]:7:2);
writeln;
writeln('Среднее арифметическое квадратов отрицательных чисел равно ',s/k:0:2);
end.