profile
Опубликовано 4 года назад по предмету Информатика от Safrion

Ввести двумерный массив 4х4, найти произведение элементов главной диагонали матрицы, а так же сумму элементов подобных диагоналей

Спасайте, ребята

  1. Ответ
    Ответ дан yasadc
    uses crt;
    const n=4;
    m=4;
    var a:array[1..n,1..m] of integer;
    s,i,j,p:integer;
    begin
    randomize;
    for i:=1 to n do
    for j:=1 to m do
    a[i,j] := random(99);
    for i:=1 to n do
    begin
    for j:=1 to m do
    write(a[i,j]:3);
    writeln;
    end;
    writeln;
    p:=1;
    for i:=1 to n do
    for j:=1 to m do
    if i=j then p:=p*a[i,j];
    s:=0;
    if (a[1,2]*a[2,3]*a[3,4]=p) then s:=s+a[1,2]+a[2,3]+a[3,4];
    if (a[1,3]*a[2,4]=p) then  s:=s+a[1,3]+a[2,4];
    if a[4,4]=p then   s:=s+a[4,4];
    if (a[2,1]*a[3,2]*a[4,3]=p) then  s:=s+a[2,1]+a[3,2]+a[4,3];
    if (a[1,3]*a[2,4]=p) then   s:=s+a[2,1]+a[3,2];
    if a[1,4]=p then   s:=s+a[1,4];
    writeln(s);
    end.