Перевести на c++! const mm = 5; type mat = array [1..5, 1..5] of real; {esli max vishe gl diagonali} procedure pp1(var A: mat; var p: boolean; var imax, jmax: integer); var i, j: integer; begin imax := 1; jmax := 1; for i := 1 to mm do for j :=1 to mm do begin if A[i, j] > a[imax, jmax] then begin imax := i; jmax := j end end; p := jmax > imax end; {Transponirovat matrix} procedure pp2(var A: mat); var i, j: integer; C: real; begin for i := 2 to mm do for j := 1 to i - 1 do begin C := A[i, j]; A[i, j] := A[j, i]; A[j, i] := C end end; {symma elementov str i stlb s index MAX} procedure pp3(var A: mat; imax, jmax: integer; var S: real); var i: integer; begin s := 0; for i := 1 to mm do s := s + A[i, jmax] + A[imax, i] end; {glav modul} var S: real; i, j, imax, jmax: integer; p: boolean; const a: mat = ((9, 1, 1, 2, 3), (4, 6, 7, 8, 4), (5, 1, 1, 1, 1), (1, 1, 1, 1, 1), (1, 1, 2, 1, 1)); begin writeln('isxodnaya matriza'); for i := 1 to mm do begin for j := 1 to mm do write(' ', a[i, j]:8:1); writeln end; pp1(A, p, imax, jmax); writeln('MAX element: A[', imax, ', ', jmax, '] = ', a[imax, jmax]:0:1); if p then begin pp2(A); writeln('Transponirovannaya matrix'); for i := 1 to mm do begin for j := 1 to mm do write(' ', a[i, j]:8:1); writeln end end else begin pp3(A, imax, jmax, S); writeln('Symma elementov s index MAX elementa = ', s:0:1) end; readln end.
const int mm = 5;
typedef float mat[5][5];
void pp1(mat& A, bool& p, int& imax, int& jmax) {
imax = 1;
jmax = 1;
for (int i = 0; i < mm; i++) {
for (int j = 0; j < mm; j++) {
if (A[i][j] > A[imax][jmax]) {
imax = i;
jmax = j;
}
}
}
p = jmax > imax;
}
void pp2(mat& A) {
float C;
for (int i = 1; i < mm; i++) {
for (int j = 0; j < i; j++) {
C = A[i][j];
A[i][j] = A[j][i];
A[j][i] = C;
}
}
}
void pp3(mat& A, int imax, int jmax, float& S) {
S = 0;
for (int i = 0; i < mm; i++) {
S += A[i][jmax] + A[imax][i];
}
}
int main() {
mat a = {{9, 1, 1, 2, 3},
{4, 6, 7, 8, 4},
{5, 1, 1, 1, 1},
{1, 1, 1, 1, 1},
{1, 1, 2, 1, 1}};
int imax, jmax;
bool p;
float S;
std::cout << "isxodnaya matriza" << std::endl;
for (int i = 0; i < mm; i++) {
for (int j = 0; j < mm; j++) {
std::cout << " " << a[i][j] << " ";
}
std::cout << std::endl;
}
pp1(a, p, imax, jmax);
std::cout << "MAX element: A[" << imax << ", " << jmax << "] = " << a[imax][jmax] << std::endl;
if (p) {
pp2(a);
std::cout << "Transponirovannaya matrix" << std::endl;
for (int i = 0; i < mm; i++) {
for (int j = 0; j < mm; j++) {
std::cout << " " << a[i][j] << " ";
}
std::cout << std::endl;
}
} else {
pp3(a, imax, jmax, S);
std::cout << "Symma elementov s index MAX elementa = " << S << std::endl;
}
return 0;
}