From 77bfb2ccd3152c1f41d43dc192ba86ca8fd0f72f Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Fri, 21 Feb 2025 17:50:16 +0100 Subject: =?UTF-8?q?Ajout=20de=20la=20semaine=20des=20cours=20du=2014=20au?= =?UTF-8?q?=2021=20f=C3=A9vrier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tme/semaine3/21_pierre_feuille_ciseaux | Bin 0 -> 15840 bytes .../tme/semaine3/21_pierre_feuille_ciseaux.c | 73 +++++++++++++++++++++ .../informatique/tme/semaine4/23_temperature.c | 40 +++++++++++ .../informatique/tme/semaine4/23_temperature_bis.c | 26 ++++++++ .../informatique/tme/semaine4/23_temperature_ter.c | 41 ++++++++++++ .../informatique/tme/semaine4/24_insertion.c | 41 ++++++++++++ semestre 2/informatique/tme/semaine4/26_fusion.c | 22 +++++++ 7 files changed, 243 insertions(+) create mode 100755 semestre 2/informatique/tme/semaine3/21_pierre_feuille_ciseaux create mode 100644 semestre 2/informatique/tme/semaine3/21_pierre_feuille_ciseaux.c create mode 100644 semestre 2/informatique/tme/semaine4/23_temperature.c create mode 100644 semestre 2/informatique/tme/semaine4/23_temperature_bis.c create mode 100644 semestre 2/informatique/tme/semaine4/23_temperature_ter.c create mode 100644 semestre 2/informatique/tme/semaine4/24_insertion.c create mode 100644 semestre 2/informatique/tme/semaine4/26_fusion.c (limited to 'semestre 2/informatique/tme') diff --git a/semestre 2/informatique/tme/semaine3/21_pierre_feuille_ciseaux b/semestre 2/informatique/tme/semaine3/21_pierre_feuille_ciseaux new file mode 100755 index 0000000..56adb13 Binary files /dev/null and b/semestre 2/informatique/tme/semaine3/21_pierre_feuille_ciseaux differ diff --git a/semestre 2/informatique/tme/semaine3/21_pierre_feuille_ciseaux.c b/semestre 2/informatique/tme/semaine3/21_pierre_feuille_ciseaux.c new file mode 100644 index 0000000..7aed5e2 --- /dev/null +++ b/semestre 2/informatique/tme/semaine3/21_pierre_feuille_ciseaux.c @@ -0,0 +1,73 @@ +#include +#include +#include +#include + +#define PIERRE 0 +#define FEUILLE PIERRE+1 +#define CISEAUX FEUILLE+1 + +#define MAX_TRY 3 + +int choix_ordinateur(){ + return rand()%3; +} + +int choix_joueur(){ + int i = 0; + scanf("%d", &i); + for (int j = 0; j < MAX_TRY-1 && i < 1 && i > 3; j++) { + printf("\nCe n'est pas une bonne valeur !\n"); + } + if (i < 1 && i > 3) return choix_ordinateur(); + return i-1; +} + +char* get_name(int coup) { + char *s; + if (coup == FEUILLE) s = "feuille"; + else if (coup == PIERRE) s = "pierre"; + else s = "ciseaux"; + char* v = malloc(25 * sizeof(char)); + strcpy(v, s); + return v; +} + +void score(int joueur, int ordinateur, int * score_joueur, int * score_ordinateur){ + printf("\nLe joueur gagnant est..."); + if (joueur > ordinateur || (joueur == PIERRE && ordinateur == CISEAUX)) { + printf(" vous !\n"); + char* cj = get_name(joueur); + char* co = get_name(ordinateur); + printf("Vous avez joué %s ce qui bat son %s", cj, co); + free(cj); + free(co); + (*score_joueur)++; + } else if (joueur < ordinateur || (ordinateur == PIERRE && joueur == CISEAUX)) { + printf(" l'ordinateur !\n"); + char* cj = get_name(joueur); + char* co = get_name(ordinateur); + printf("Il a joué %s ce qui bat votre %s\n", co, cj); + free(cj); + free(co); + (*score_ordinateur)++; + } else { + printf(" oh non, la partie est nulle !"); + } + printf("\n"); +} + +void jeu(){ + int score_ordinateur = 0, score_joueur = 0; + while (score_ordinateur < 3 && score_joueur < 3) { + printf("Choissez votre coup :\n- 1 pour pierre\n- 2 pour feuille\n- 3 pour ciseaux\n"); + score(choix_joueur(), choix_ordinateur(), &score_joueur, &score_ordinateur); + } + printf("Scores finaux:\n- Joueur : %d\n- Ordinateur : %d\n\n", score_joueur, score_ordinateur); +} + +int main(){ + srand(time(NULL)); + jeu(); + return 0; +} 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 +#include +#include + +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 + +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 + +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 + +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 +#include + +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; +} -- cgit v1.2.3