begin var n := ReadlnInteger('n = '); var m := ReadlnInteger('m = '); var rand := ReadlnInteger('Для ручного ввода нажмите 0');
if rand = 0 then begin a := new integer[m, n]; for var i := 0 to m-1 do for var j := 0 to n-1 do a[i, j] := ReadlnInteger('a[' + i + ',' + j + '] = '); end else a := MatrixRandom(m, n, 1, 100); Println(a);
var b := ArrGen(n, x -> 1); for var i := 0 to m-1 do for var j := 0 to n-1 do if j mod 2 = 0 then b[j] := b[j] * a[i, j];
b.Where((x, i)-> i mod 2 = 0).SortedDescending().Println(); end.
a: array [,] of integer;
begin
var n := ReadlnInteger('n = ');
var m := ReadlnInteger('m = ');
var rand := ReadlnInteger('Для ручного ввода нажмите 0');
if rand = 0 then begin
a := new integer[m, n];
for var i := 0 to m-1 do
for var j := 0 to n-1 do
a[i, j] := ReadlnInteger('a[' + i + ',' + j + '] = ');
end
else a := MatrixRandom(m, n, 1, 100);
Println(a);
var b := ArrGen(n, x -> 1);
for var i := 0 to m-1 do
for var j := 0 to n-1 do
if j mod 2 = 0 then
b[j] := b[j] * a[i, j];
b.Where((x, i)-> i mod 2 = 0).SortedDescending().Println();
end.
Так как язык не указан, приведу пример на SWI-Prolog.
Код:
read_int(Int) :- read(Int), integer(Int).split_int_by_numbers(0, []) :- !.split_int_by_numbers(N, [Number|Ints]) :- Number is mod(N, 10), RestN is div(N, 10), split_int_by_numbers(RestN, Ints).test_to_div(_, []).test_to_div(N, [Number|Ints]) :- mod(N, Number) =:= 0, test_to_div(N, Ints). test(Int) :- split_int_by_numbers(Int, Numbers), test_to_div(Int, Numbers), write(Int), write(" - Yes!"), nl.test(Int) :- write(Int), write(" - No!"), nl.?- read_int(Int), test(Int).