aboutsummaryrefslogtreecommitdiff
path: root/semestre 2/informatique/tme/semaine4/23_temperature_ter.c
blob: 398d3ffef0230517e77ef144015e1975eb13bc1e (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
#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;
}