diff options
| author | Anhgelus Morhtuuzh <anhgelus@anhgelus.world> | 2025-02-21 17:50:16 +0100 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <anhgelus@anhgelus.world> | 2025-02-21 17:50:25 +0100 |
| commit | 77bfb2ccd3152c1f41d43dc192ba86ca8fd0f72f (patch) | |
| tree | 798ab77b1c1608ef8cc6e56f3d12778c0844b03b /semestre 2/informatique/tme/semaine4/23_temperature.c | |
| parent | a1a5447b8b040b100bad89766066ae4ba8d6d920 (diff) | |
Ajout de la semaine des cours du 14 au 21 février
Diffstat (limited to 'semestre 2/informatique/tme/semaine4/23_temperature.c')
| -rw-r--r-- | semestre 2/informatique/tme/semaine4/23_temperature.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/semestre 2/informatique/tme/semaine4/23_temperature.c b/semestre 2/informatique/tme/semaine4/23_temperature.c new file mode 100644 index 0000000..3762987 --- /dev/null +++ b/semestre 2/informatique/tme/semaine4/23_temperature.c @@ -0,0 +1,40 @@ +#include <stdlib.h> +#include <time.h> +#include <stdio.h> + +void init_temp(float tab[31]){ + for (int i = 0; i < 31; i++)tab[i] = (float) (rand()%500-200)/10; +} + +float moy_temp(float tab[31]){ + float s = 0; + for (int i = 0; i < 31; i++) s += tab[i]; + return s / 31; +} + +float moy_temp_neg(float tab[31]){ + float s = 0; + int n = 0; + for (int i = 0; i < 31; i++) { + if (tab[i] < 0){ + s += tab[i]; + n++; + } + } + if (n == 0) { + return 1; + } + return s/n; +} + +int main() { + srand(time(NULL)); + float tab[31]; + init_temp(tab); + for (int i = 0; i < 31; i++) printf("%.2f\t", tab[i]); + printf("\n%.2f\n", moy_temp(tab)); + float v = moy_temp_neg(tab); + if (v > 0) printf("Aucune température en dessous de zero."); + else printf("%.2f", v); + return 0; +} |
