Vla_DOS

Untitled

Jun 5th, 2022
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include<conio.h>
  5. #include<cctype>
  6. using namespace std;
  7.  
  8. int MaxElement(int** mas, int n) {
  9.     int max, i, j;
  10.     max = mas[0][0];
  11.     for (i = 0; i < n; i++)
  12.     {
  13.         for (j = 0; j < n; j++)
  14.         {
  15.             if (mas[i][j] > max)
  16.             {
  17.                 max = mas[i][j];
  18.             }
  19.         }
  20.     }
  21.     return max;
  22. }
  23. void Rand(int** mas, int n) {
  24.     for (int i = 0; i < n; i++) {
  25.         for (int j = 0; j < n; j++) {
  26.             mas[i][j] = rand() % 50 + 1;
  27.         }
  28.     }
  29. }
  30. void Show(int** mas, int n) {
  31.     for (int i = 0; i < n; i++) {
  32.         for (int j = 0; j < n; j++) {
  33.             cout << mas[i][j] << "\t";
  34.         }
  35.         cout << "\n";
  36.     }
  37. }
  38. void main()
  39. {
  40.     setlocale(LC_ALL, "ukr");
  41.     int n = 5, max;
  42.     int q = 0, w, e, i, j;
  43.     e = 0;
  44.  
  45.     int** mas1 = new int* [n];
  46.     for (int i = 0; i < n; i++)
  47.         mas1[i] = new int[n];
  48.  
  49.     int** mas2 = new int* [n];
  50.     for (int i = 0; i < n; i++)
  51.         mas2[i] = new int[n];
  52.  
  53.     Rand(mas1, n);
  54.     Rand(mas2, n);
  55.     cout << "Масив №1:" << endl;
  56.     Show(mas1, n);
  57.  
  58.     cout << "Масив №2:" << endl;
  59.     Show(mas2, n);
  60.     cout << "--------------------------\n";
  61.  
  62.     cout << "\nПiвсума найбiльших елементiв: " << (MaxElement(mas1, n) + MaxElement(mas2, n)) / 2 << endl;
  63.     system("pause");    
  64. }
Advertisement
Add Comment
Please, Sign In to add comment