summaryrefslogtreecommitdiff
path: root/1_anno/Programmazione_1/ex1_27_01_20.cc
blob: 1b0e529d45ee2a7a16eef4212e3bfd86bb882653 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<iostream>
#define N 3
#define M 4
using namespace std;

float* func(int** Q, float a, float b) {
    float* arr = new float[M];

    int a_i = static_cast<int>(a);
    int b_i = static_cast<int>(b);

    for(int i = 0; i < M; ++i) {
        short counter{};
        float sum{};
        for(int j = 0; j < N; ++j) {
            if(Q[j][i]) {
                if(Q[j][i] >= a_i && Q[j][i] <= b_i) {
                    ++counter;
                    sum += Q[j][i];
                }
            }
        }

        arr[i] = (sum / static_cast<float>(counter));
    }

    return arr;
}

int main() {
    int** A = new int*[N];
    for(int i = 0; i < N; ++i) {
        A[i] = new int[M];
        for(int j = 0; j < M; ++j)
            A[i][j] = 24;
    }

    float* arr = func(A, 1.0, 33.0);    
    
    for(int j = 0; j < M; ++j)
        cout << arr[j] << ' ';

    delete[] A;
    delete arr;

    return 0;
}