#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <iostream>
#include <iomanip>
#define N 5
#define M 6
using namespace std;
void swap(int& n1, int& n2);
int main(int argc, char* argv[])
{
float** L = new float*[N];
memset((void*)L, 0x00, N * 4);
for (int z1 = 0; z1 < N; z1++)
{
L[z1] = new float[M];
for (int z2 = 0; z2 < M; z2++)
{
int sign = rand() % 2 + 1;
L[z1][z2] = ((float)rand() / RAND_MAX) * ((sign > 1) ? (-1) : 1);
cout << std::fixed << std::setw(4) << std::setprecision(2) << L[z1][z2] << " ";
}
cout << endl;
}
cout << endl;
swap(L[0][0],L[N-1][M-1]);
float sum = 0.00;
for (int i = 0; i < N; i++)
for (int j = 0; j < M; j++)
if (L[i][j] < 0) sum+=L[i][j];
for (int t1 = 0; t1 < N; t1++)
{
for (int t2 = 0; t2 < M; t2++)
cout << std::fixed << std::setw(4) << std::setprecision(2) << L[t1][t2] << " ";
cout << endl;
}
cout << endl;
cout << "Result = " << std::fixed << std::setw(4) << std::setprecision(2) << sum << endl;
return 0;
}
void swap(int& n1, int& n2)
{ int _tn = n1; n1 = n2; n2 = _tn; }