#include <iostream>
#include <iomanip>
using namespace std;
int** matrCreate(int n)
{
int** M;
M = new int *[n];
for (int i = 0; i < n; i++)
M[i] = new int [n];
return M;
}
void matrInit(int** M, int n)
srand(time(0));
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
M[i][j] = rand()%199 - 99 ;
void matrPrint(int** M, int n)
cout << setw(5) << M[i][j];
cout << endl;
void matrTransform(int** M, int n)
int im, jm, max = -1000, s = 0;
if (M[i][j] > max)
max = M[i][j];
im = i;
jm = j;
if (i == j)
s += M[i][j];
M[im][jm] = s;
void clearMem(int** M, int n)
delete [] M[i];
delete [] M;
int main()
int n;
cin >> n;
int **A;
A = matrCreate(n);
matrInit(A, n);
matrPrint(A, n);
matrTransform(A, n);
clearMem;
return 0;
#include <iostream>
#include <iomanip>
using namespace std;
int** matrCreate(int n)
{
int** M;
M = new int *[n];
for (int i = 0; i < n; i++)
M[i] = new int [n];
return M;
}
void matrInit(int** M, int n)
{
srand(time(0));
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
M[i][j] = rand()%199 - 99 ;
}
void matrPrint(int** M, int n)
{
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
cout << setw(5) << M[i][j];
cout << endl;
}
}
void matrTransform(int** M, int n)
{
int im, jm, max = -1000, s = 0;
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
if (M[i][j] > max)
{
max = M[i][j];
im = i;
jm = j;
}
if (i == j)
s += M[i][j];
}
}
M[im][jm] = s;
}
void clearMem(int** M, int n)
{
for (int i = 0; i < n; i++)
{
delete [] M[i];
}
delete [] M;
}
int main()
{
int n;
cin >> n;
int **A;
A = matrCreate(n);
matrInit(A, n);
matrPrint(A, n);
cout << endl;
matrTransform(A, n);
matrPrint(A, n);
clearMem;
return 0;
}