Задано матрицы С, В, А размерности (5х5). Составить программу, в которой с помощью функции находить произведение отрицательных элементов матрицы. Введение матриц и вывод результатов выполнить в основной программе — Pascal(Паскаль)

const n=5;
type
 mas = Array[1..n,1..n] of integer;
var
  a,b,c:mas;
  i,j:integer;
 
  function GetValue(q:mas):Integer;
  var
    i,j,p,cnt:integer;
  begin
    p:=1;cnt:=0;
    for i:=1 to n do
      for j:=1 to n do
        if q[i,j]<0 then 
    begin
     p:=p*q[i,j];
     inc(cnt);
    end;
        if (cnt=0) then
          p:=0;
    GetValue:=p;
  end;
 
begin
  { TODO -oUser -cConsole Main : Insert code here }
  // заполняем массив а
  for i:=1 to n do
    for j:=1 to n do
      begin
        write('a[',i,',',j,']=');
        Readln(a[i,j]);
      end;
  Writeln('Массив a');
  for i:=1 to n do
    begin
      for j:=1 to n do
        write(a[i,j], ' ');
      writeln;
    end;
  Writeln('Произведение отрицательных:', GetValue(a));
  Writeln;
  // заполняем массив b
  for i:=1 to n do
    for j:=1 to n do
      begin
        write('b[',i,',',j,']=');
        Readln(b[i,j]);
      end;
  Writeln('Массив b');
  for i:=1 to n do
    begin
      for j:=1 to n do
        write(b[i,j], ' ');
      writeln;
    end;
  Writeln('Произведение отрицательных:', GetValue(b));
  Writeln;
  // заполняем массив c
  for i:=1 to n do
    for j:=1 to n do
      begin
        write('c[',i,',',j,']=');
        Readln(c[i,j]);
      end;
  Writeln('Массив c');
  for i:=1 to n do
    begin
      for j:=1 to n do
        write(c[i,j], ' ');
      writeln;
    end;
  Writeln('Произведение отрицательных:', GetValue(c));
end.

Leave a Comment

− 1 = 1