const n=5; var a:array[1..n,1..n] of integer; x:array[1..n] of double; i,j,k:byte; begin Randomize; Writeln('*** Исходный массив ***'); for i:=1 to n do begin for j:=1 to n do begin a[i,j]:=Random(51)-25; Write(a[i,j]:4) end; Writeln end; Writeln('*** Массив x ***'); for j:=1 to n do begin x[j]:=0; k:=0; for i:=1 to n do if a[i,j] mod 2=0 then begin x[j]:=x[j]+a[i,j]; Inc(k) end; if k>0 then x[j]:=x[j]/k; Write(x[j]:0:5,' ') end; Writeln end.
Язык не указан → приведу пример на SWI-Prolog.
Код%Файл string_sortin.plsort([], [], _).sort([Head|Tail], Ordered, Qrd) :- sort(Tail, SubSorted, Qrd), put(Head, SubSorted, Sorted), order(Sorted, [], Ordered, Qrd).put(X, [], [X]).put(X, [H|T], [X,H|T]) :- compare(>, X, H).put(X, [H|T], [H|R]) :- put(X, T, R).order(X, _, X, ">").order([], R, R, "<").order([H|T], B, R, "<") :- order(T, [H|B], R, "<").select(">", Bufer, Bufer, _, ">").select("<", Bufer, Bufer, _, "<").select(S, Bufer, [S|Bufer], Ord, Ord).input_strings(Input, Bufer, Strings, Ord, ROrd) :- compare(=, Ord, "="), read_string(Input, "\n", "\r", _, String), select(String, Bufer, SS, Ord, OO), input_strings(Input, SS, Strings, OO, ROrd).input_strings(_, Strings, Strings, Ord, Ord). ?- current_input(Input), input_strings(Input, [], Strings, "=", Ord), sort(Strings, [R|_], Ord), writeln(R).const
n=5;
var
a:array[1..n,1..n] of integer;
x:array[1..n] of double;
i,j,k:byte;
begin
Randomize;
Writeln('*** Исходный массив ***');
for i:=1 to n do begin
for j:=1 to n do begin
a[i,j]:=Random(51)-25;
Write(a[i,j]:4)
end;
Writeln
end;
Writeln('*** Массив x ***');
for j:=1 to n do begin
x[j]:=0; k:=0;
for i:=1 to n do
if a[i,j] mod 2=0 then begin
x[j]:=x[j]+a[i,j]; Inc(k)
end;
if k>0 then x[j]:=x[j]/k;
Write(x[j]:0:5,' ')
end;
Writeln
end.
Тестовое решение:
*** Исходный массив ***
-10 18 -8 -15 5
-21 -18 6 -2 9
-7 22 -4 3 14
21 16 -10 -18 -9
17 3 -14 -18 12
*** Массив x ***
-10.00000 9.50000 -6.00000 -12.66667 13.00000