Turn the matrix D[i,j] m,n so that the column with the minimum sum of elements and the column with the maximum sum are swapped.

Amount finding is wrong what is wrong?

 #include<iostream> using namespace std; int main() { float D[10][10], Sum[10], copD[10][10], Min, Max; int m, n, jmin, jmax, mesto = 0; ///////////??*????? ????? cout << "Enter n \n"; cin >> m; cout << "Enter m \n"; cin >> n; for( int i = 0; i < n; i++ ) { for( int j = 0; j < m; j++ ) { cout << "Enter D[" << i << "][" << j << "]\n"; cin >> D[i][j]; } } /////SUMA for( int j = 0; j < m; j++ ) { Sum[j] = D[mesto][j]; Sum[j] += + D[mesto + 1][j]; mesto++; cout << "Summ:" << Sum[j] << endl; } ////MIN for( jmin = 0; jmin < m; jmin++ ) { if( Sum[jmin] > Sum[jmin + 1] ) { Min = Sum[jmin + 1]; } else { Min = Sum[jmin]; break; } } ////MAX for( jmax = 0; jmax < m; jmax++ ) { if( Sum[jmax] < Sum[jmax + 1] ) { Max = Sum[jmax + 1]; } else { Max = Sum[jmax]; break; } } for( int i = 0; i < n; i++ ) { for( int j = 0; j < m; j++ ) { copD[i][j] = D[i][j]; } } cout << "Jmin: " << jmin; cout << "Jmax: " << jmax << endl; cout << "Max " << Max << endl; cout << "Jmin: " << jmin << "Jmax: " << jmax << endl; cout << "Min " << Min << endl; for( int i = 0; i < n; i++ ) { copD[i][jmin] = copD[i][jmax]; //out << "Mass : " << copD[i][j]; copD[i][jmax] = D[i][jmin]; } for( int i = 0; i < n; i++ ) { for( int j = 0; j < m; j++ ) { cout << "Mass D [" << i << "][" << j << "] " << copD[i][j] << endl; } } system( "pause" ); } 

Closed due to the fact that off-topic participants Vlad from Moscow , Kromster , aleksandr barakin , αλεχολυτ , HamSter Nov 3, 'at 13:12 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Kromster, αλεχολυτ, HamSter
If the question can be reformulated according to the rules set out in the certificate , edit it .

1 answer 1

Amused even the beginning:

 cout << "Enter n \n"; cin >> m; 

Enter one, read another ... And yet - you are not confused in your variables? Give them the "talking" names - row , in the extreme case, stroka much clearer than i .

I did not begin to rake your code;

 #include<iostream> using namespace std; int main() { double D[10][10]; int rows, cols; cout << "Enter rows: "; cin >> rows; cout << "Enter cols: "; cin >> cols; for( int i = 0; i < rows; i++ ) { for( int j = 0; j < cols; j++ ) { cout << "Enter D[" << i << "][" << j << "]: "; cin >> D[i][j]; } } int minidx = 0, maxidx = 0; double min = 0.0, max, sum; for(int i = 0; i < rows; ++i) min += D[i][0]; max = min; for(int c = 1; c < cols; ++c) { sum = 0.0; for(int r = 0; r < rows; ++r) sum += D[r][c]; if (sum < min) { min = sum; minidx = c; } else if (sum > max) { max = sum; maxidx = c; } } cout << "Jmin: " << minidx << endl; cout << "Jmax: " << maxidx << endl; cout << "Min: " << min << endl; cout << "Max: " << max << endl; for(int r = 0; r < rows; ++r ) { double tmp = D[r][minidx]; D[r][minidx] = D[r][maxidx]; D[r][maxidx] = tmp; } for(int r = 0; r < rows; ++r ) { for(int c = 0; c < cols; ++c) { cout << "D [" << r << "][" << c << "] " << D[r][c] << endl; } } system( "pause" ); }