Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <ctime>
- #include <iomanip>
- #include <cstdlib>
- using namespace std;
- int * vector(int **mas, int len_y, int len_x);
- int main() {
- int len_x = 1, len_y = 1;
- setlocale(LC_ALL, "Rus");
- cout << "Укажите ширину и длину массива: ";
- cin >> len_x >> len_y;
- int **array = new int*[len_y];
- for (int x = 0; x<len_y; x++) {
- array[x] = new int[len_x];
- }
- for (int y = 0; y<len_y; y++) {
- for (int x = 0; x < len_x; x++)
- {
- array[y][x] = rand() % 100 + 1;
- cout << setw(4) << setprecision(2) << array[y][x] << " ";
- }
- cout << endl;
- }
- int *vec = vector(array, len_y, len_x);
- for (int x = 0; x < len_y; x++)
- {
- cout << setw(4) << setprecision(2) << vec[x] << " ";
- }
- return 0;
- for (int c = 0; c<len_y; c++)
- {
- delete[]array[c];
- }
- delete[]array;
- }
- int * vector(int **mas, int len_y, int len_x) {
- int * vec = new int[len_y];
- int n = 0;
- int buf = 0;
- for (int y = 0; y<len_y; y++) {
- buf = mas[y][0];
- for (int x = 1; x<len_x; x++) {
- if (mas[y][x]>buf) {
- buf = mas[y][x];
- }
- }
- vec[n] = buf;
- n++;
- }
- return vec;
- delete[]vec;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement