#include <iostream>
#include <time.h>
#include <algorithm>
#include <vector>
#include <variant>
using namespace std;
pair<int**, vector<int>> pow_matrix_after_zero_line_by_line(int** mat, int n, int m) {
vector<int> line_matrix;
vector<int> pow_line_matrix;
int icounter = 0;
int i_temp;
for (size_t i = 0; i < n; i++) {
for (size_t j = 0; j < m; j++) {
line_matrix.push_back(mat[i][j]);
}
cout << endl;
auto it = find(line_matrix.begin(), line_matrix.end(), 0);
i_temp = it - line_matrix.begin() + 1;
if (i_temp < line_matrix.size() - 1) {
cout << "Элемент '0' найден на позиции: " << i_temp << endl;
pow_line_matrix.push_back(1);
for (size_t j = i_temp; j < m; j++) {
pow_line_matrix[icounter] *= mat[i][j];
icounter++;
line_matrix.clear();
else {
cout << "Элемент '0' не найден в строке матрицы под номером: " << i << endl;
pow_line_matrix.push_back(-1);
return make_pair(mat, pow_line_matrix);
void printMat(int** mat, int n, int m)
{
for (int i = 0; i < n; i++) {
cout << "[" << i << "] ";
for (int j = 0; j < m; j++)
cout << mat[i][j] << " ";
int main()
srand(time(0));
setlocale(LC_ALL, "Russian");
int n, m;
cout << "Введите максимальный размер строк в матрице" << endl;
cin >> n;
cout << "Введите максимальный размер колонок в матрице" << endl;
cin >> m;
int** matrix = new int* [n];
int** matrix2 = new int* [n];
vector<int> pow_matrix_line_by_line;
pair<int**, vector<int>> returnf1;
for (int i = 0; i < n; ++i) {
matrix[i] = new int[m];
matrix2[i] = new int[m];
for (size_t j = 0; j < m; j++)
matrix[i][j] = rand() % 5;
printMat(matrix, n, m);
returnf1 = pow_matrix_after_zero_line_by_line(matrix, n, m);
matrix2 = returnf1.first;
pow_matrix_line_by_line = returnf1.second;
printMat(matrix2, n, m);
cout << "Произведение построчно в матрице после нуля:" << endl;
for (int i = 0; i < pow_matrix_line_by_line.size(); i++) {
cout << "[" << i << "] " << pow_matrix_line_by_line[i] << endl;
return -4;
------------------------------------------------------------
pair<float**, float> pow_matrix_after_zero_line_by_line(float** mat, int n, int m) {
vector<float> line_matrix;
float pow_after_zero_matrix;
bool key = false;
i_temp = it - line_matrix.begin()+1;
if (i_temp < line_matrix.size()+1) {
pow_after_zero_matrix = 1;
pow_after_zero_matrix *= mat[i][j];
key = true;
if (!key) {
return make_pair(mat, pow_after_zero_matrix);
float round1(float var)
float value = (int)(var * 100 + .5);
return (float)value / 100;
float rand_FloatRange(float a, float b)
return round1(((b - a) * ((float)rand() / RAND_MAX)) + a);
void printMat(float** mat, int n, int m)
float** matrix = new float* [n];
float** matrix2 = new float* [n];
float pow_matrix;
pair<float**, float> returnf1;
matrix[i] = new float[m];
matrix2[i] = new float[m];
matrix[i][j] = rand_FloatRange(1,10);
matrix[rand() % n][rand() % m] = 0;
pow_matrix = returnf1.second;
cout << "Произведение построчно в матрице после нуля:" << pow_matrix << endl;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
//ПОСТРОЧНОЕ
#include <iostream>
#include <time.h>
#include <algorithm>
#include <vector>
#include <variant>
using namespace std;
pair<int**, vector<int>> pow_matrix_after_zero_line_by_line(int** mat, int n, int m) {
vector<int> line_matrix;
vector<int> pow_line_matrix;
int icounter = 0;
int i_temp;
for (size_t i = 0; i < n; i++) {
for (size_t j = 0; j < m; j++) {
line_matrix.push_back(mat[i][j]);
}
cout << endl;
auto it = find(line_matrix.begin(), line_matrix.end(), 0);
i_temp = it - line_matrix.begin() + 1;
if (i_temp < line_matrix.size() - 1) {
cout << "Элемент '0' найден на позиции: " << i_temp << endl;
pow_line_matrix.push_back(1);
for (size_t j = i_temp; j < m; j++) {
pow_line_matrix[icounter] *= mat[i][j];
}
icounter++;
line_matrix.clear();
}
else {
cout << "Элемент '0' не найден в строке матрицы под номером: " << i << endl;
pow_line_matrix.push_back(-1);
icounter++;
line_matrix.clear();
}
}
return make_pair(mat, pow_line_matrix);
}
void printMat(int** mat, int n, int m)
{
for (int i = 0; i < n; i++) {
cout << "[" << i << "] ";
for (int j = 0; j < m; j++)
cout << mat[i][j] << " ";
cout << endl;
}
}
int main()
{
srand(time(0));
setlocale(LC_ALL, "Russian");
int n, m;
cout << "Введите максимальный размер строк в матрице" << endl;
cin >> n;
cout << "Введите максимальный размер колонок в матрице" << endl;
cin >> m;
int** matrix = new int* [n];
int** matrix2 = new int* [n];
vector<int> pow_matrix_line_by_line;
pair<int**, vector<int>> returnf1;
for (int i = 0; i < n; ++i) {
matrix[i] = new int[m];
matrix2[i] = new int[m];
}
for (size_t i = 0; i < n; i++) {
for (size_t j = 0; j < m; j++)
matrix[i][j] = rand() % 5;
}
printMat(matrix, n, m);
returnf1 = pow_matrix_after_zero_line_by_line(matrix, n, m);
matrix2 = returnf1.first;
pow_matrix_line_by_line = returnf1.second;
cout << endl;
printMat(matrix2, n, m);
cout << "Произведение построчно в матрице после нуля:" << endl;
for (int i = 0; i < pow_matrix_line_by_line.size(); i++) {
cout << "[" << i << "] " << pow_matrix_line_by_line[i] << endl;
}
return -4;
}
------------------------------------------------------------
//ПОСЛЕДОВАТЕЛЬНОЕ
#include <iostream>
#include <time.h>
#include <algorithm>
#include <vector>
#include <variant>
using namespace std;
pair<float**, float> pow_matrix_after_zero_line_by_line(float** mat, int n, int m) {
vector<float> line_matrix;
float pow_after_zero_matrix;
int icounter = 0;
int i_temp;
bool key = false;
for (size_t i = 0; i < n; i++) {
for (size_t j = 0; j < m; j++) {
line_matrix.push_back(mat[i][j]);
}
cout << endl;
auto it = find(line_matrix.begin(), line_matrix.end(), 0);
i_temp = it - line_matrix.begin()+1;
if (i_temp < line_matrix.size()+1) {
cout << "Элемент '0' найден на позиции: " << i_temp << endl;
pow_after_zero_matrix = 1;
for (size_t j = i_temp; j < m; j++) {
pow_after_zero_matrix *= mat[i][j];
}
key = true;
line_matrix.clear();
}
else {
cout << "Элемент '0' не найден в строке матрицы под номером: " << i << endl;
if (!key) {
icounter++;
}
else {
for (size_t j = 0; j < m; j++) {
pow_after_zero_matrix *= mat[i][j];
}
}
line_matrix.clear();
}
}
return make_pair(mat, pow_after_zero_matrix);
}
float round1(float var)
{
float value = (int)(var * 100 + .5);
return (float)value / 100;
}
float rand_FloatRange(float a, float b)
{
return round1(((b - a) * ((float)rand() / RAND_MAX)) + a);
}
void printMat(float** mat, int n, int m)
{
for (int i = 0; i < n; i++) {
cout << "[" << i << "] ";
for (int j = 0; j < m; j++)
cout << mat[i][j] << " ";
cout << endl;
}
}
int main()
{
srand(time(0));
setlocale(LC_ALL, "Russian");
int n, m;
cout << "Введите максимальный размер строк в матрице" << endl;
cin >> n;
cout << "Введите максимальный размер колонок в матрице" << endl;
cin >> m;
float** matrix = new float* [n];
float** matrix2 = new float* [n];
float pow_matrix;
pair<float**, float> returnf1;
for (int i = 0; i < n; ++i) {
matrix[i] = new float[m];
matrix2[i] = new float[m];
}
for (size_t i = 0; i < n; i++) {
for (size_t j = 0; j < m; j++)
matrix[i][j] = rand_FloatRange(1,10);
}
matrix[rand() % n][rand() % m] = 0;
printMat(matrix, n, m);
returnf1 = pow_matrix_after_zero_line_by_line(matrix, n, m);
matrix2 = returnf1.first;
pow_matrix = returnf1.second;
cout << endl;
printMat(matrix2, n, m);
cout << "Произведение построчно в матрице после нуля:" << pow_matrix << endl;
return -4;
}