aboutsummaryrefslogtreecommitdiff
path: root/semestre 2/informatique/tme/semaine4/23_temperature_ter.c
diff options
context:
space:
mode:
Diffstat (limited to 'semestre 2/informatique/tme/semaine4/23_temperature_ter.c')
-rw-r--r--semestre 2/informatique/tme/semaine4/23_temperature_ter.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/semestre 2/informatique/tme/semaine4/23_temperature_ter.c b/semestre 2/informatique/tme/semaine4/23_temperature_ter.c
new file mode 100644
index 0000000..398d3ff
--- /dev/null
+++ b/semestre 2/informatique/tme/semaine4/23_temperature_ter.c
@@ -0,0 +1,41 @@
+#include <stdio.h>
+
+float moy_temp(float *tab, int nbj){
+ float s = 0;
+ for (int i = 0; i < nbj; i++) s += tab[i];
+ return s / nbj;
+}
+
+float moy_temp_gel(float *tab, int nbj){
+ float s = 0;
+ int n = 0;
+ for (int i = 0; i < nbj; i++) {
+ if (tab[i] < 0){
+ s += tab[i];
+ n++;
+ }
+ }
+ if (n == 0) return 1;
+ return s/n;
+}
+
+int main() {
+ float tab[31] = {-4.8, 0.5, 2.2, -4.0, -2.6, -9.7, 8.8, 6.9, -1.8};
+ float moy_gel;
+ int i, nbj = 9;
+
+ /*scanf("%d", &nbj);
+ for (i = 0; i < nbj; i++) {
+ scanf("%f", &tab[i]);
+ }*/
+ printf("temperature moyenne sur les %d derniers jours : %.2f\n", nbj, moy_temp(tab, nbj));
+ moy_gel = moy_temp_gel(tab, nbj);
+ printf("moy_gel %f", moy_gel);
+ if (moy_gel <= 0) {
+ printf("temperature moyenne sur les jours de gel : %.2f\n", moy_gel);
+ }
+ else {
+ printf("Aucune temperature au-dessous de zero.\n");
+ }
+ return 0;
+}