diff options
author | Santo Cariotti <dcariotti24@gmail.com> | 2020-01-27 11:09:38 +0100 |
---|---|---|
committer | Santo Cariotti <dcariotti24@gmail.com> | 2020-01-27 11:09:38 +0100 |
commit | b38334cda43f3edd49208e5f63cb9dc3845b0a20 (patch) | |
tree | f511ddfa564a497962e41bd132abce136cda22a4 /I_anno | |
parent | 9a0cb71572997c38115cc6f85f7c76f9767f1d0b (diff) |
ex 1 27/01/20
Diffstat (limited to 'I_anno')
-rw-r--r-- | I_anno/Programmazione_1/ex1_27_01_20.cc | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/I_anno/Programmazione_1/ex1_27_01_20.cc b/I_anno/Programmazione_1/ex1_27_01_20.cc new file mode 100644 index 0000000..1b0e529 --- /dev/null +++ b/I_anno/Programmazione_1/ex1_27_01_20.cc @@ -0,0 +1,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; +} |