Advertisement
JewishCat

Untitled

May 18th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <ctime>
  4. #include <iomanip>
  5. #include <cstdlib>
  6. using namespace std;
  7. int * vector(int **mas, int len_y, int len_x);
  8. int main() {
  9.     int len_x = 1, len_y = 1;
  10.     setlocale(LC_ALL, "Rus");
  11.     cout << "Укажите ширину и длину массива: ";
  12.     cin >> len_x >> len_y;
  13.  
  14.     int **array = new int*[len_y];
  15.     for (int x = 0; x<len_y; x++) {
  16.         array[x] = new int[len_x];
  17.     }
  18.    
  19.     for (int y = 0; y<len_y; y++) {
  20.         for (int x = 0; x < len_x; x++)
  21.         {
  22.             array[y][x] = rand() % 100 + 1;
  23.             cout << setw(4) << setprecision(2) << array[y][x] << "  ";
  24.         }
  25.         cout << endl;
  26.     }
  27.     int *vec = vector(array, len_y, len_x);
  28.  
  29.     for (int x = 0; x < len_y; x++)
  30.     {
  31.         cout << setw(4) << setprecision(2) << vec[x] << "  ";
  32.     }
  33.     return 0;
  34.  
  35.     for (int c = 0; c<len_y; c++)
  36.     {
  37.         delete[]array[c];
  38.  
  39.     }
  40.     delete[]array;
  41.    
  42. }
  43. int * vector(int **mas, int len_y, int len_x) {
  44.     int * vec = new int[len_y];
  45.     int n = 0;
  46.     int buf = 0;
  47.     for (int y = 0; y<len_y; y++) {
  48.         buf = mas[y][0];
  49.         for (int x = 1; x<len_x; x++) {
  50.             if (mas[y][x]>buf) {
  51.                 buf = mas[y][x];
  52.             }
  53.         }
  54.         vec[n] = buf;
  55.         n++;
  56.     }
  57.    
  58.     return vec;
  59.     delete[]vec;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement