Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <iomanip>
- #include <ctime>
- using namespace std;
- void main()
- {
- srand(time(NULL));
- const int N = 5, M = 5;
- int a[N][M], max;
- double sr;
- char code;
- cout << "Input 1 to randomize amtrix and 2 for manual input" << endl;
- cin >> code;
- if (code == '1' || code == '2') {
- if (code == '1') {
- for (int i = 0; i < N; i++) {
- for (int j = 0; j < M; j++) {
- a[i][j] = rand() % 25;
- cout << setw(4) << a[i][j] << " ";
- }
- cout << endl;
- }
- }
- else {
- for (int i = 0; i < N; i++)
- for (int j = 0; j < M; j++) {
- cin >> a[i][j];
- }
- }
- cout << endl;
- for (int j = 0; j < M; j++) {
- max = INT32_MIN;
- sr = 0;
- for (int i = 0; i < N; i++) {
- sr += a[i][j];
- if (a[i][j] > max)
- max = a[i][j];
- }
- sr /= N;
- if (max - sr > a[0][j]) {
- for (int i = 0; i < N; i++) {
- a[i][j] = 1;
- }
- }
- }
- for (int i = 0; i < N; i++) {
- for (int j = 0; j < M; j++) {
- cout << setw(4) << a[i][j] << " ";
- }
- cout << endl;
- }
- }
- else {
- cout << "Unrecognized input" << endl;
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement