Дана вещественная матрица размерности n*m. Вывести номера строк, содержащих больше положительных элементов чем отрицательных. Решите пожалуйста на языке Pacal
Answers & Comments
Amarina9
Program strok; uses crt; const m=3; n=4; var i,j,pos,neg: integer; a:array[1..n, 1..m] of real; begin for i:=1 to n do for j:=1 to m do read(a[i,j]); for i:= 1 to n do begin neg:= 0; pos:= 0; for j:= 1 to m do begin if a[i,j] < 0 then Inc(neg) else Inc(pos); end; if pos > neg then Write(IntToStr(i),' '); end; ReadLn; end.
1 votes Thanks 1
TheSpyZ
for i:=1 to 1 do for j:=1 to 5 do if a[i,j]>0 then inc(t); if t>=3 then writeln('1'); end; begin for i:=2 to 2 do for j:=1 to 5 do if a[i,j]>0 then inc(k); if k>=3 then writeln('2'); end; begin for i:=3 to 3 do for j:=1 to 5 do if a[i,j]>0 then inc(b); if b>=3 then writeln('3'); end;
Answers & Comments
uses crt;
const
m=3;
n=4;
var i,j,pos,neg: integer;
a:array[1..n, 1..m] of real;
begin
for i:=1 to n do
for j:=1 to m do
read(a[i,j]);
for i:= 1 to n do begin
neg:= 0;
pos:= 0;
for j:= 1 to m do begin
if a[i,j] < 0 then Inc(neg)
else Inc(pos);
end;
if pos > neg then
Write(IntToStr(i),' ');
end;
ReadLn;
end.
for j:=1 to 5 do
if a[i,j]>0 then inc(t);
if t>=3 then writeln('1');
end;
begin
for i:=2 to 2 do
for j:=1 to 5 do
if a[i,j]>0 then inc(k);
if k>=3 then writeln('2');
end;
begin
for i:=3 to 3 do
for j:=1 to 5 do
if a[i,j]>0 then inc(b);
if b>=3 then writeln('3');
end;