Given the matrix A (n, m). Form an array B (m), each element of which is the arithmetic average of the corresponding column of the matrix A.


int _tmain(int argc, _TCHAR* argv[]) { setlocale(0,"RUS"); const int n=3, m=4; int arr_A[3][4]={}; for(int i=0; i<n; i++){ for(int j=0; j<m; j++){ arr_A[i][j]=rand()%50; } } for(int i=0; i<n; i++){ for(int j=0; j<m; j++){ cout <<" "<< arr_A[i][j]; } cout <<endl; } int sum=0; int arr_B[m]={}; for(int l=0; l<n; l++){ for(int v=0; v<m; v++){ 

Closed due to the fact that off-topic participants Kromster , 0xdb , Jarvis_J , Kosta B. , July 15 '18 at 21:13 .

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, 0xdb, Jarvis_J, Kosta B., ߊߚߤߘ
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • And the problem is what? - pavel
  • five
    Really easy. What is your question? - AnT
  • Write the code please here is where I am stuck now - SaLderMAN0
  • int _tmain (int argc, _TCHAR * argv []) {setlocale (0, "RUS"); const int n = 3, m = 4; int arr_A [3] [4] = {}; for (int i = 0; i <n; i ++) {for (int j = 0; j <m; j ++) {arr_A [i] [j] = rand ()% 50; }} for (int i = 0; i <n; i ++) {for (int j = 0; j <m; j ++) {cout << "" << arr_A [i] [j]; } cout << endl; } int sum = 0; int arr_B [m] = {}; for (int l = 0; l <n; l ++) {for (int v = 0; v <m; v ++) { - SaLderMAN0

1 answer 1

 for(int col = 0; col < m; ++col) { B[col] = 0; for(int row = 0; row < n; ++row) B[col] += A[row][col]; B[col] /= n; } 
  • Not bro did not understand in the array B you need to write the arithmetic mean of the columns of the array A !!! - SaLderMAN0
  • Well, bro, in nature hesitated ... And what did I do? - Harry
  • Yes, the wrong numbers show where I need to be corrected anyway ((( - SaLderMAN0
  • Maybe the integer division is used? Instead of floating point? - Harry
  • 2
    @Harry: Nothing to indulge freeloaders. - VladD