using namespace std;
#include <iostream>
#include <clocale>
#include <cstdlib>
#include <iomanip>
#include <string>
#include <ctime>
void massinit(int* mass, int masssizeM, int masssizeN) {
for (int i = 0; i < masssizeM * masssizeN; i++) {
mass[i] = rand() % 90 + 10;
}
void massout(int* mass, int masssizeM, int masssizeN) {
for (int i = 0; i < masssizeM; i++) {
for (int j = i * masssizeN; j < (i + 1) * masssizeN; j++) {
cout << setw(3) << mass[j] << " ";
cout << endl;
cout << endl << endl;
int twodimcount(int* mass, int masssizeM, int masssizeN) {
int returnval = 0;
int avgvalue = 0;
avgvalue += mass[j];
returnval += avgvalue;
avgvalue /= masssizeN;
mass[j] += avgvalue;
cout << "Новый массив:" << endl;
massout(mass, masssizeM, masssizeN);
return returnval;
int main() {
setlocale(LC_ALL, "rus");
system("chcp 1251");
srand(time(0));
int M = rand() % 8 + 2;
int N = rand() % 8 + 2;
int a = 0;
int* mainmass = new int[M * N];
massinit(mainmass, M, N);
cout << "Изначальный массив:" << endl;
massout(mainmass, M, N);
a = twodimcount(mainmass, M, N);
cout << "Сумма средних значений строк новой матрицы: " << a << endl;
delete[] mainmass;
system("pause");
return 0;
Заполняется случайными числами, можно сделать пользовательский ввод, заменив arr[i][j] = rand() % 100; на cin >> arr[i][j];
#include <random>
#include <cmath>
void printArr(int** arr, size_t sizeX, size_t sizeY) {
for (size_t i = 0; i < sizeX; ++i) {
for (size_t j = 0; j < sizeY; ++j) {
cout << arr[i][j] << " ";
void func1(int** arr, size_t sizeX, size_t sizeY) {
if (arr[i][j] % 2 == 1) {
arr[i][j] *= 2;
void func2(int** arr, size_t sizeX, size_t sizeY) {
int32_t min = INT32_MAX;
if (arr[i][j] < min) {
min = arr[i][j];
cout << i << ": sqrt(" << min << ") = " << sqrt(min) << endl;
const size_t sizeX = 4, sizeY = 3;
int** arr = new int*[4];
arr[i] = new int[sizeY];
arr[i][j] = rand() % 100;
printArr(arr, sizeX, sizeY);
func1(arr, sizeX, sizeY);
func2(arr, sizeX, sizeY);
using namespace std;
#include <iostream>
#include <clocale>
#include <cstdlib>
#include <iomanip>
#include <string>
#include <ctime>
void massinit(int* mass, int masssizeM, int masssizeN) {
for (int i = 0; i < masssizeM * masssizeN; i++) {
mass[i] = rand() % 90 + 10;
}
}
void massout(int* mass, int masssizeM, int masssizeN) {
for (int i = 0; i < masssizeM; i++) {
for (int j = i * masssizeN; j < (i + 1) * masssizeN; j++) {
cout << setw(3) << mass[j] << " ";
}
cout << endl;
}
cout << endl << endl;
}
int twodimcount(int* mass, int masssizeM, int masssizeN) {
int returnval = 0;
for (int i = 0; i < masssizeM; i++) {
int avgvalue = 0;
for (int j = i * masssizeN; j < (i + 1) * masssizeN; j++) {
avgvalue += mass[j];
}
returnval += avgvalue;
avgvalue /= masssizeN;
for (int j = i * masssizeN; j < (i + 1) * masssizeN; j++) {
mass[j] += avgvalue;
}
}
cout << "Новый массив:" << endl;
massout(mass, masssizeM, masssizeN);
return returnval;
}
int main() {
setlocale(LC_ALL, "rus");
system("chcp 1251");
srand(time(0));
int M = rand() % 8 + 2;
int N = rand() % 8 + 2;
int a = 0;
int* mainmass = new int[M * N];
massinit(mainmass, M, N);
cout << "Изначальный массив:" << endl;
massout(mainmass, M, N);
a = twodimcount(mainmass, M, N);
cout << "Сумма средних значений строк новой матрицы: " << a << endl;
delete[] mainmass;
system("pause");
return 0;
}
Заполняется случайными числами, можно сделать пользовательский ввод, заменив arr[i][j] = rand() % 100; на cin >> arr[i][j];
#include <iostream>
#include <random>
#include <ctime>
#include <cmath>
using namespace std;
void printArr(int** arr, size_t sizeX, size_t sizeY) {
for (size_t i = 0; i < sizeX; ++i) {
for (size_t j = 0; j < sizeY; ++j) {
cout << arr[i][j] << " ";
}
cout << endl;
}
}
void func1(int** arr, size_t sizeX, size_t sizeY) {
for (size_t i = 0; i < sizeX; ++i) {
for (size_t j = 0; j < sizeY; ++j) {
if (arr[i][j] % 2 == 1) {
arr[i][j] *= 2;
}
}
}
}
void func2(int** arr, size_t sizeX, size_t sizeY) {
for (size_t i = 0; i < sizeX; ++i) {
int32_t min = INT32_MAX;
for (size_t j = 0; j < sizeY; ++j) {
if (arr[i][j] < min) {
min = arr[i][j];
}
}
cout << i << ": sqrt(" << min << ") = " << sqrt(min) << endl;
}
}
int main() {
srand(time(0));
const size_t sizeX = 4, sizeY = 3;
int** arr = new int*[4];
for (size_t i = 0; i < sizeX; ++i) {
arr[i] = new int[sizeY];
for (size_t j = 0; j < sizeY; ++j) {
arr[i][j] = rand() % 100;
}
}
printArr(arr, sizeX, sizeY);
func1(arr, sizeX, sizeY);
cout << endl;
printArr(arr, sizeX, sizeY);
func2(arr, sizeX, sizeY);
}