Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main()
- {
- int m=3, n=3;
- int a[m][n] = {
- {1,1,3},
- {4,5,6},
- {7,2,5}
- };
- for (int i = 0; i < m; ++i){
- for (int j = 0; j < n; ++j){
- // a[i][j] = i*n+j;
- cout<< setw(2) <<a[i][j]<<'\t';}
- cout<<endl;
- }
- for (int i = 0; i < 12; ++i) cout<<'-';
- int min, max;
- bool hasMin, hasMax;
- hasMin = hasMax = 0;
- for (int i = 0, j, _min; i < m; ++i) {
- _min = hasMin ? min:a[i][0];
- for (j = 0 ; j < n; ++j){
- if (a[i][j]%2 == 0) break;
- if (a[i][j] < _min) _min = a[i][j];
- }
- if (j==n) {
- min = _min;
- hasMin = true;
- }
- }
- for (int j = 0, chet = 0, nech = 0, _max ; j < n; ++j) {
- _max = hasMax ? max:a[0][j];
- for (int i = 0 ; i < m; ++i){
- if (a[i][j] > _max) _max = a[i][j];
- if (a[i][j]%2 == 0) chet++;
- else nech++;
- }
- if (nech>chet) {
- hasMax = true;
- max = _max;
- }
- }
- if (hasMin) cout<<endl<<"min:" << setw(2) << min;
- else cout<<endl<< "netu_min";
- if (hasMax) cout<<endl<<"max:" << setw(2) << max;
- else cout<<endl<< "netu_max";
- if (hasMin && hasMax) cout<<endl<<"z = "<< min + max;
- else cout<<endl<< "netu_z";
- }
Add Comment
Please, Sign In to add comment