#include <bits/stdc++.h>
using namespace std;
int main()
{
srand((unsigned)time(NULL));
int m, n;
double sum, min;
cout << "Enter a matrix size:" << "\n";
cout << "m = ";
cin >> m;
cout << "n = ";
cin >> n;
double** B = new double*[m];
for (int i = 0; i < m; i++)
B[i] = new double[n];
}
cout << "A random matrix:" << "\n";
cout.precision(2);
sum = 0;
min = 10.0;
for (int j = 0; j < n; j++)
B[i][j] = -10 + 20.0 / RAND_MAX * rand(); //[-10; 10]
if (B[i][j] < min)
min = B[i][j];
cout.width(6);
cout << fixed << B[i][j];
sum += min;
cout << "\n";
cout << "Searched sum: " << fixed << sum << "\n";
delete [] B[i];
delete [] B;
system("pause");
return 0;
Объяснение:
#include <bits/stdc++.h>
using namespace std;
int main()
{
srand((unsigned)time(NULL));
int m, n;
double sum, min;
cout << "Enter a matrix size:" << "\n";
cout << "m = ";
cin >> m;
cout << "n = ";
cin >> n;
double** B = new double*[m];
for (int i = 0; i < m; i++)
{
B[i] = new double[n];
}
cout << "A random matrix:" << "\n";
cout.precision(2);
sum = 0;
for (int i = 0; i < m; i++)
{
min = 10.0;
for (int j = 0; j < n; j++)
{
B[i][j] = -10 + 20.0 / RAND_MAX * rand(); //[-10; 10]
if (B[i][j] < min)
min = B[i][j];
cout.width(6);
cout << fixed << B[i][j];
}
sum += min;
cout << "\n";
}
cout << "Searched sum: " << fixed << sum << "\n";
for (int i = 0; i < m; i++)
{
delete [] B[i];
}
delete [] B;
system("pause");
return 0;
}
Объяснение: