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 | |
| parent | a1a5447b8b040b100bad89766066ae4ba8d6d920 (diff) | |
Ajout de la semaine des cours du 14 au 21 février
Diffstat (limited to 'semestre 2/informatique/tme/semaine4')
5 files changed, 170 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; +} diff --git a/semestre 2/informatique/tme/semaine4/23_temperature_bis.c b/semestre 2/informatique/tme/semaine4/23_temperature_bis.c new file mode 100644 index 0000000..97d7d69 --- /dev/null +++ b/semestre 2/informatique/tme/semaine4/23_temperature_bis.c @@ -0,0 +1,26 @@ +#include <stdio.h> + +void conversion(float *tabC, int *tabF, int n) { + for (int i = 0; i < n; i++){ + tabC[i] =(float) 5/9 * (tabF[i] - 32); + } +} + +int main() { + int tabF[31]= {27, 29, 20, 25, 27, 23, 37, 29, 23, 46, 50, 39, 32, 34, 27}; + float tabC[31]; + int i, nb = 15; + + /*scanf("%d", &nb); + for (i = 0; i < nb; i++) { + scanf("%d", &tabF[i]); + }*/ + + conversion(tabC, tabF, 31); + for (i = 0; i < nb; i++) { + printf("%.1f ", tabC[i]); + } + printf("\n"); + return 0; +} + 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; +} diff --git a/semestre 2/informatique/tme/semaine4/24_insertion.c b/semestre 2/informatique/tme/semaine4/24_insertion.c new file mode 100644 index 0000000..4f44f90 --- /dev/null +++ b/semestre 2/informatique/tme/semaine4/24_insertion.c @@ -0,0 +1,41 @@ +#include <stdio.h> + +int indiceInsert(int *tab, int taille, int nbEl, int el){ + if (nbEl >= taille) return -1; + int i = 0; + while (i < nbEl && tab[i] <= el) { + if (tab[i] == el) return -1; + i++; + } + return i; +} + +int insertElt(int el, int *tab, int taille, int *nb) { + int ind = indiceInsert(tab, taille, *nb, el); + if (ind == -1) return 0; + int prev = 0; + int set = 0; + for (int i = ind; i < *nb+1; i++){ + if (set == 0) { + set = 1; + prev = tab[i]; + tab[i] = el; + } else { + int t = prev; + prev = tab[i]; + tab[i] = t; + } + } + (*nb)++; + return 1; +} + +int main(){ + int tab[10] = {0, 1, 3, 5}; + int taille = 10; + int nb = 4; + printf("%d\n\n", insertElt(-1, tab, taille, &nb)); + for (int i = 0; i < taille; i++){ + printf("%d. %d\n", i, tab[i]); + } +} diff --git a/semestre 2/informatique/tme/semaine4/26_fusion.c b/semestre 2/informatique/tme/semaine4/26_fusion.c new file mode 100644 index 0000000..731011f --- /dev/null +++ b/semestre 2/informatique/tme/semaine4/26_fusion.c @@ -0,0 +1,22 @@ +#include <stdio.h> +#include <stdlib.h> + +int *fusion(int *tab1, int t1, int *tab2, int t2) { + int *ntab = malloc(sizeof(int) * (t1+t2)); + int i_1 = 0; + int i_2 = 0; + for (int i = 0; i < t1+t2; i++) { + if (i_1 < t1 && i_2 < t2) ntab[i] = tab1[i_1] < tab2[i_2] ? tab1[i_1++] : tab2[i_2++]; + else if (i_1 < t1) ntab[i] = tab1[i_1++]; + else ntab[i] = tab2[i_2++]; + } + return ntab; +} + +int main() { + int tab1[6] = {1, 2, 4, 5, 7, 8}; + int tab2[5] = {0, 0, 3, 6, 9}; + int *ntab = fusion(tab1, 6, tab2, 5); + for (int i = 0; i < 5+6; i++) printf("%d- %d\n", i, ntab[i]); + return 0; +} |
