что-то типа этого:
const n = 8, m = 8;
var
A: array[1..n,1..m] of integer;
i, j, sum, product: integer;
isnotnull: boolean;
begin
randomize;
writeln('Случайная матрица:'); for i:=1 to n do begin
for j:=1 to m do begin
A[i,j] := random(51) - 25;
write(A[i,j]:5);
end;
writeln;
end; sum := 0;
for i:=1 to n do
if A[i,n-i+1] < 0 then
sum := sum + A[i,n-i+1];
writeln('Сумма отрицательных элементов побочной диагонали = ', sum); product := 1;
isnotnull := False;
for i:=1 to n-1 do
for j:=2 to n do
if (j > i) and (A[i,j] <> 0) then begin
isnotnull := True;
product := product * A[i,j];
end;
if isnotnull
writeln('Произведение ненулевых элементов в области выше главной диагонали = ', product)
else
writeln('Ненулевых элементов в области выше главной диагонали нет.', product); readln;
end.
для c++
Объяснение:
#include <iostream>
#include <iomanip>
#include<ctime>
#include<cstdlib>
using namespace std;
int main()
{
setlocale(0, "");
srand(time(0));
int n,m, i, j;
cout << "Введите размер массива, n = ";
cin >> n;
cout << "m = ";
cin >> m;
int** arr = new int* [n];
for (i = 0; i < n; i++)
{arr[i] = new int[m];}
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
arr[i][j] = rand() % 20 - 10 ;
}
}
cout << "Исходный массив:" << endl;
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
cout << arr[i][j] << "\t";
cout << endl;
}
for (int i = 0; i < n; i++)
delete[]arr[i];
system("pause");
return 0;
}