Advertisement
Kentoo

E#3

Jan 16th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <ctime>
  5.  
  6. using namespace std;
  7.  
  8. void main()
  9. {
  10.     srand(time(NULL));
  11.     const int N = 5, M = 5;
  12.     int a[N][M], max;
  13.     double sr;
  14.     char code;
  15.     cout << "Input 1 to randomize amtrix and 2 for manual input" << endl;
  16.     cin >> code;
  17.     if (code == '1' || code == '2') {
  18.         if (code == '1') {
  19.             for (int i = 0; i < N; i++) {
  20.                 for (int j = 0; j < M; j++) {
  21.                     a[i][j] = rand() % 25;
  22.                     cout << setw(4) << a[i][j] << " ";
  23.                 }
  24.                 cout << endl;
  25.             }
  26.         }
  27.         else {
  28.             for (int i = 0; i < N; i++)
  29.                 for (int j = 0; j < M; j++) {
  30.                     cin >> a[i][j];
  31.                 }
  32.         }
  33.         cout << endl;
  34.         for (int j = 0; j < M; j++) {
  35.             max = INT32_MIN;
  36.             sr = 0;
  37.             for (int i = 0; i < N; i++) {
  38.                 sr += a[i][j];
  39.                 if (a[i][j] > max)
  40.                     max = a[i][j];
  41.             }
  42.             sr /= N;
  43.             if (max - sr > a[0][j]) {
  44.                 for (int i = 0; i < N; i++) {
  45.                     a[i][j] = 1;
  46.                 }
  47.             }
  48.         }
  49.         for (int i = 0; i < N; i++) {
  50.             for (int j = 0; j < M; j++) {
  51.                 cout << setw(4) << a[i][j] << " ";
  52.             }
  53.             cout << endl;
  54.         }
  55.     }
  56.     else {
  57.         cout << "Unrecognized input" << endl;
  58.     }
  59.     system("pause");
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement