V
victory
Определить функцию определения столбца с наибольшей суммой модулей его элементов, функцию определения минимального элемента столбца и функцию формирования требуемого массива.
#include <cstdlib>
#include <iostream>
#include <cstdio>
int main ( ) {
const int m = 5, n = 7;
int arr[m][n];
int sum_abs[n];
for ( int i = 0; i < m; ++i ) {
for ( int j = 0; j < n; ++j ) { arr[j] = rand() % 20; printf("%2i ", arr[j]); }
std::cout << std::endl;
}
for ( int j = 0; j < n; ++j ) {
sum_abs[j] = 0;
for ( int i = 0; i < m; ++i )
sum_abs[j] += abs(arr[j]);
}
int max_sum = sum_abs[0];
int max_count = 1;
for ( int i = 0; i < n; ++ i )
if ( max_sum < sum_abs ) { max_sum = sum_abs; max_count = 1; }
else if ( max_sum == sum_abs ) ++max_count;
int * minimals = new int[max_count];
for ( int min_i = 0, i = 0; i < n; ++i ) {
if ( sum_abs != max_sum ) continue;
minimals[min_i] = arr[0];
for ( int j = 1; j < m; ++j )
if ( minimals[min_i] > arr[j] ) minimals[min_i] = arr[j];
++min_i;
}
std::cout << std::endl << "Minimals: ";
for ( int i = 0; i < max_count; ++i ) std::cout << minimals << " ";
std::cout << std::endl;
system("pause");
return 0;
}
#include <cstdlib>
#include <iostream>
#include <cstdio>
int main ( ) {
const int m = 5, n = 7;
int arr[m][n];
int sum_abs[n];
for ( int i = 0; i < m; ++i ) {
for ( int j = 0; j < n; ++j ) { arr[j] = rand() % 20; printf("%2i ", arr[j]); }
std::cout << std::endl;
}
for ( int j = 0; j < n; ++j ) {
sum_abs[j] = 0;
for ( int i = 0; i < m; ++i )
sum_abs[j] += abs(arr[j]);
}
int max_sum = sum_abs[0];
int max_count = 1;
for ( int i = 0; i < n; ++ i )
if ( max_sum < sum_abs ) { max_sum = sum_abs; max_count = 1; }
else if ( max_sum == sum_abs ) ++max_count;
int * minimals = new int[max_count];
for ( int min_i = 0, i = 0; i < n; ++i ) {
if ( sum_abs != max_sum ) continue;
minimals[min_i] = arr[0];
for ( int j = 1; j < m; ++j )
if ( minimals[min_i] > arr[j] ) minimals[min_i] = arr[j];
++min_i;
}
std::cout << std::endl << "Minimals: ";
for ( int i = 0; i < max_count; ++i ) std::cout << minimals << " ";
std::cout << std::endl;
system("pause");
return 0;
}