Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <ctime>
- #include <iomanip>
- using namespace std;
- /*
- Дана матрица. Получить вектор, в котором содержатся максимальные элементы из каждой строки матрицы
- */
- void bol_mas(int **mas);
- int main()
- {
- srand(time(0)); // генерация случайных чисел
- int **ptrarray = new int*[10]; // две строки в массиве
- for (int count = 0; count < 10; count++)
- ptrarray[count] = new int[10]; // и пять столбцов создание динамического массива вещественных чисел на десять элементов
- for (int x = 0; x < 10; x++) {
- for (int y = 0; y < 10; y++) {
- ptrarray[x][y] = (rand() % 10 + 1) / float((rand() % 10 + 1));
- cout << setprecision(2) << ptrarray[x][y] << " ";
- }
- cout << endl;
- }
- cout << endl;
- bol_mas(ptrarray);
- for (int x = 0; x < 10; x++)
- delete[] ptrarray[x]; // высвобождение памяти
- cout << endl;
- system("pause");
- return 0;
- }
- void bol_mas(int **mas) {
- int *outmas = new int[10];
- int buf;
- for (int x = 0; x < 10; x++) {
- buf = 0;
- for (int y = 0; y < 9; y++) {
- if (mas[x][y]>mas[x][y + 1]) {
- if (buf < mas[x][y]) {
- buf = mas[x][y];
- }
- }
- }
- outmas[x] = buf;
- }
- for (int i = 0; i < 10; i++)
- cout << setprecision(2) << outmas[i] << " ";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement