//PascalABC.NET 3.1 сборка 1219 procedure PrintMatrix(a: array[,] of integer); begin for var i := a.GetLowerBound(0) to a.GetUpperBound(0) do begin writeln; for var j := a.GetLowerBound(1) to a.GetUpperBound(1) do write(a[i, j], ' '); end; writeln; end;
begin var a := MatrixRandom(9, 9, 10, 99); PrintMatrix(a); var i := (a.GetLowerBound(0) + a.GetUpperBound(0)) div 2 + (a.GetLowerBound(0) + a.GetUpperBound(0)) mod 2; var j := (a.GetLowerBound(1) + a.GetUpperBound(1)) div 2 + (a.GetLowerBound(1) + a.GetUpperBound(1)) mod 2; writeln('A[', i, ', ', j, '] = ', a[i, j]); end.
#include <iostream> #include <iomanip> int main() { using namespace std; const int N = 4; const int M = 4; int Y[N][M];
//как-нибудь заполняем матрицу for (int i = 0; i < N; ++i) for (int j = 0; j < M; ++j) Y[i][j] = (i + 1) * (j + 1);
//выведем её на экран for (int i = 0; i < N; ++i) { for (int j = 0; j < M; ++j) cout << setw(3) << Y[i][j]; cout << endl; }
//находим сумму элементов побочной диагонали int S = 0; for (int i = 0; i < N; ++i) for (int j = 0; j < M; ++j) if (j == M - 1 - i) S = S + Y[i][j]; cout << "Sum of adverse diagonal of array: " << S << endl;
//находим сумму всех элементов матрицы int Sum = 0; for (int i = 0; i < N; ++i) for (int j = 0; j < M; ++j) Sum = Sum + Y[i][j]; cout << "Sum of all elements of array: " << Sum << endl; return 0; }
procedure PrintMatrix(a: array[,] of integer);
begin
for var i := a.GetLowerBound(0) to a.GetUpperBound(0) do
begin
writeln;
for var j := a.GetLowerBound(1) to a.GetUpperBound(1) do
write(a[i, j], ' ');
end;
writeln;
end;
begin
var a := MatrixRandom(9, 9, 10, 99);
PrintMatrix(a);
var i := (a.GetLowerBound(0) + a.GetUpperBound(0)) div 2 + (a.GetLowerBound(0) + a.GetUpperBound(0)) mod 2;
var j := (a.GetLowerBound(1) + a.GetUpperBound(1)) div 2 + (a.GetLowerBound(1) + a.GetUpperBound(1)) mod 2;
writeln('A[', i, ', ', j, '] = ', a[i, j]);
end.
#include <iomanip>
int main()
{
using namespace std;
const int N = 4;
const int M = 4;
int Y[N][M];
//как-нибудь заполняем матрицу
for (int i = 0; i < N; ++i)
for (int j = 0; j < M; ++j)
Y[i][j] = (i + 1) * (j + 1);
//выведем её на экран
for (int i = 0; i < N; ++i)
{
for (int j = 0; j < M; ++j)
cout << setw(3) << Y[i][j];
cout << endl;
}
//находим сумму элементов побочной диагонали
int S = 0;
for (int i = 0; i < N; ++i)
for (int j = 0; j < M; ++j)
if (j == M - 1 - i)
S = S + Y[i][j];
cout << "Sum of adverse diagonal of array: " << S << endl;
//находим сумму всех элементов матрицы
int Sum = 0;
for (int i = 0; i < N; ++i)
for (int j = 0; j < M; ++j)
Sum = Sum + Y[i][j];
cout << "Sum of all elements of array: " << Sum << endl;
return 0;
}