Помогите решить на с++, эти задания
Ответы
Файл заголовків main.h
#ifndef MAIN_H
#define MAIN_H
using namespace std;
void fill_matrix(float **x, int n, int m);
void find_min(float **x, int n, int m);
void sum_matrix(float **x, int n, int m);
#endif
Головний файл програми main.cpp
#include <iostream>
#include <cmath>
#include "main.h"
using namespace std;
void fill_matrix(float **x, int n, int m) {
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
x[i][j] = pow(log(9*i+j+1), 3) - exp(i);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout << x[i][j] << "\t";
}
cout << endl;
}
}
void find_min(float **x, int n, int m) {
float min = 0, min_id[1], sum = 0;
int find_j = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (x[i][j] < min) {
min = x[i][j];
find_j = j;
}
}
}
for (int i = 0; i< n; i++) {
sum += x[i][find_j];
}
min_id[0] = sum;
cout << "Min element = " << min << endl;
cout << "Min sum elements by rows = " << min_id[0] << endl;
}
void sum_matrix(float **x, int n, int m) {
float sum = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
sum+= x[i][j];
cout << "Sum = " << sum << endl;
}
int main () {
const int n = 5, m = 8;
float** matrix = new float* [n];
for (int i = 0; i< n; i++) matrix[i] = new float[m];
fill_matrix(matrix, n, m);
find_min(matrix, n, m);
sum_matrix(matrix, n, m);
}
#include <iostream>
#include <cmath
using namespace std;
void fill_matrix(float **x, int n, int m) {
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
x[i][j] = pow(log(9*i+j+1), 3) - exp(i);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout << x[i][j] << "\t";
}
cout << endl;
}
}
void find_min(float **x, int n, int m) {
float min = 0, min_id[1], sum = 0;
int find_j = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (x[i][j] < min) {
min = x[i][j];
find_j = j;
}
}
}
for (int i = 0; i< n; i++) {
sum += x[i][find_j];
}
min_id[0] = sum;
cout << "Min element = " << min << endl;
cout << "Min sum elements by rows = " << min_id[0] << endl;
}
void sum_matrix(float **x, int n, int m) {
float sum = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
sum+= x[i][j];
cout << "Sum = " << sum << endl;
}
int main () {
const int n = 5, m = 8;
float** matrix = new float* [n];
for (int i = 0; i< n; i++) matrix[i] = new float[m];
fill_matrix(matrix, n, m);
find_min(matrix, n, m);
sum_matrix(matrix, n, m);
}