summaryrefslogtreecommitdiff
path: root/Year_1/Programming_1/h9_2.cc
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2021-02-06 19:56:36 +0100
committerSanto Cariotti <santo@dcariotti.me>2021-02-06 19:56:36 +0100
commitd2edbc38cac8da52f58c5cd3da6c0c625fa05736 (patch)
treea51e9a4e56fc9d4c7c9e37576dceedca3a0c72b4 /Year_1/Programming_1/h9_2.cc
parent98f34040820dc3a964b7be59a698323e8cc6c8a3 (diff)
conf: rename
Diffstat (limited to 'Year_1/Programming_1/h9_2.cc')
-rw-r--r--Year_1/Programming_1/h9_2.cc32
1 files changed, 32 insertions, 0 deletions
diff --git a/Year_1/Programming_1/h9_2.cc b/Year_1/Programming_1/h9_2.cc
new file mode 100644
index 0000000..0e9c853
--- /dev/null
+++ b/Year_1/Programming_1/h9_2.cc
@@ -0,0 +1,32 @@
+#include <iostream>
+
+// Array NxM e numero p. Stampare le medie per ogni colonna dispari dei valori x <= p
+
+int main() {
+ const short N = 4, M = 4;
+ int p = 9;
+ int A[N][M] = {
+ {3, 1, 5, 5},
+ {5, 3, 1, 5},
+ {8, 7, 4, 5},
+ {4, 7, 4, 5},
+ };
+ // Condizione necessaria per matrici in cui M != N
+ short cond = (N < M) ? N : M;
+
+ for(int i = 1; i < cond; i+=2) {
+ int sum = 0, c = 0;
+ for(int j = 0; j < M; ++j) {
+ if(A[j][i] <= p) {
+ sum += A[j][i];
+ c++;
+ }
+ }
+
+ if(c > 0) {
+ std::cout << static_cast<float>(sum)/c << '\n';
+ }
+ }
+
+ return 0;
+}