Const m=4; n=15; var i,j,j0: integer; a:array[1..m,1..n] of integer; jExit,iExit:Boolean; begin Randomize; for i:=1 to m do begin writeln; for j:=1 to n do begin a[i,j]:=random(2); write(a[i,j]:2) end end; writeln; j:=0; jExit:=false; repeat j:=j+1; i:=1; iExit:=false; if a[i,j]=0 then begin repeat i:=i+1; if a[i,j]<>0 then iExit:=true until iExit or (i=m); if i=m then jExit:=true end until jExit or (j=n); if a[i,j]=0 then writeln('Нулевой столбец ',j) else writeln('Нет нулевых столбцов'); end.
var
i,j,j0: integer;
a:array[1..m,1..n] of integer;
jExit,iExit:Boolean;
begin
Randomize;
for i:=1 to m do begin
writeln;
for j:=1 to n do begin
a[i,j]:=random(2);
write(a[i,j]:2)
end
end;
writeln;
j:=0; jExit:=false;
repeat
j:=j+1; i:=1; iExit:=false;
if a[i,j]=0 then begin
repeat
i:=i+1;
if a[i,j]<>0 then iExit:=true
until iExit or (i=m);
if i=m then jExit:=true
end
until jExit or (j=n);
if a[i,j]=0 then writeln('Нулевой столбец ',j)
else writeln('Нет нулевых столбцов');
end.
Тестовый пример:
0 1 1 1 1 0 1 0 1 0 0 0 0 0 1
0 0 1 0 1 0 0 0 1 1 0 0 0 0 0
1 1 0 0 0 1 0 1 1 1 1 1 0 1 1
1 1 1 0 1 0 1 0 0 1 0 1 0 1 0
Нулевой столбец 13
Так как язык не указан, приведу пример на 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).