#include <iostream>
#include <ctime>
using namespace std;
void randMas(int **a, int n, int m)
{
srand(time(0));
for(int i=0; i<n; i++)
for(int j=0; j<m; j++)
a[i][j] = rand() %10 + 1;
}
int sumItemOnMain(int **a, int n, int m)
int p,sum = 0;
if (n<m)
p=n;
else
p=m;
for(int i; i<p; i++)
sum+=a[i][i];
return sum;
int main()
int n,m,sum;
cin>>n>>m;
int** Mas = new int *[n];
for (int i = 0; i < n; i++)
Mas[i] = new int [m];
randMas(Mas,n,m);
sum = sumItemOnMain(Mas,n,m);
cout<<sum;
return 0;
#include <iostream>
#include <ctime>
using namespace std;
void randMas(int **a, int n, int m)
{
srand(time(0));
for(int i=0; i<n; i++)
for(int j=0; j<m; j++)
a[i][j] = rand() %10 + 1;
}
int sumItemOnMain(int **a, int n, int m)
{
int p,sum = 0;
if (n<m)
p=n;
else
p=m;
for(int i; i<p; i++)
sum+=a[i][i];
return sum;
}
int main()
{
int n,m,sum;
cin>>n>>m;
int** Mas = new int *[n];
for (int i = 0; i < n; i++)
Mas[i] = new int [m];
randMas(Mas,n,m);
sum = sumItemOnMain(Mas,n,m);
cout<<sum;
return 0;
}