більше шпагеті!
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
void get_Matrix(vector<vector<float>>& matrix, int n, int m);
void print_Matrix(vector<vector<float>> const& matrix);
int amount_Of_Row(vector<vector<float>> const& matrix);
float arithmetic_Mean(vector<vector<float>> const& matrix, int zadana_velichyna);
void to_Triangular_View(vector<vector<float>>& matrix);
int main()
{
vector<vector<float>> Matrix_Example = { {2, 3, 4, 1}, {1, 5, 2, 2}, {-3, 2, 1, 3}, {5, 4, 3, 2}};
int n, m;
cout <<"vedite kil'kist' ryudkiv: ";
cin >> n;
cout <<"vedite kil'kist' stovpchikiv: ";
cin >> m;
cout << endl;
vector<vector<float>> Matrix(n, vector<float>(m));
get_Matrix(Matrix, n, m);
print_Matrix(Matrix);
cout <<"amount_Of_Row = " << amount_Of_Row(Matrix) << endl;
int zadana_Velichyna;
cout << "zadana_Velichyna = ";
cin >> zadana_Velichyna;
cout << "arithmetic_Mean = " << arithmetic_Mean(Matrix, zadana_Velichyna) << endl;
to_Triangular_View(Matrix);
print_Matrix(Matrix);
}
void get_Matrix(vector<vector<float>>& matrix, int n, int m)
{
float number = 0;
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
{
cin >> number;
matrix[i][j] = number;
}
};
void print_Matrix(vector<vector<float>> const& matrix)
{
for(auto element_vector : matrix)
{
for(auto element : element_vector)
cout << setw(6) << setprecision(3) << element << " ";
cout << endl;
}
cout << endl;
};
int amount_Of_Row(vector<vector<float>> const& matrix)
{
return matrix.size();
};
float arithmetic_Mean(vector<vector<float>> const& matrix, int zadana_velichyna)
{
int kilkist_spivpadin = 0;
float sum = 0;
for(auto element_vector : matrix)
for(auto element : element_vector)
{
if(element < zadana_velichyna)
{
sum += element;
kilkist_spivpadin++;
}
}
return sum / kilkist_spivpadin;
};
void to_Triangular_View(vector<vector<float>>& matrix)
{
int kilkist_stovpchikiv = matrix[0].size(), kilkist_ryadkiv = matrix.size();
float temp_koef = 0;
cout << "Size: " << kilkist_ryadkiv << "*" << kilkist_stovpchikiv << endl;
for(int ryad = 0; ryad < kilkist_ryadkiv; ryad++)
{
for(int nast_ryad = ryad + 1; nast_ryad < kilkist_ryadkiv ; nast_ryad++)
{
temp_koef = matrix[nast_ryad][ryad] / matrix[ryad][ryad];
for(int stovp = 0; stovp < kilkist_stovpchikiv; stovp++)
{
matrix[nast_ryad][stovp] = matrix[nast_ryad][stovp] - temp_koef * matrix[ryad][stovp];
}
}
}
};