From 161df9258494d80fff5c77b21fa9207cba5aa7fa Mon Sep 17 00:00:00 2001 From: Simoes Lukas Date: Tue, 22 Oct 2024 15:38:09 +0200 Subject: [PATCH] Fin du tp --- DEV1.1/CM1/exo1.c | 14 +++++++++ DEV1.1/CM1/exo2.c | 15 +++++++++ DEV1.1/CM1/exo3.c | 29 +++++++++++++++++ DEV1.1/CM1/exo4.c | 28 +++++++++++++++++ DEV1.1/CM1/exo5.c | 57 ++++++++++++++++++++++++++++++++++ DEV1.1/TP17/TP17_reponses.txt | 5 +++ DEV1.1/TP17/tests | Bin 0 -> 15504 bytes DEV1.1/TP17/tests.c | 16 ++++++++++ DEV1.1/TP19/TP19_reponses.txt | 4 +++ DEV1.1/TP19/tests.c | 34 ++++++++++++++++++++ DEV1.1/simoes_CM1.tar.gz | Bin 0 -> 1490 bytes 11 files changed, 202 insertions(+) create mode 100644 DEV1.1/CM1/exo1.c create mode 100644 DEV1.1/CM1/exo2.c create mode 100644 DEV1.1/CM1/exo3.c create mode 100644 DEV1.1/CM1/exo4.c create mode 100644 DEV1.1/CM1/exo5.c create mode 100644 DEV1.1/TP17/TP17_reponses.txt create mode 100755 DEV1.1/TP17/tests create mode 100644 DEV1.1/TP17/tests.c create mode 100644 DEV1.1/TP19/TP19_reponses.txt create mode 100644 DEV1.1/TP19/tests.c create mode 100644 DEV1.1/simoes_CM1.tar.gz diff --git a/DEV1.1/CM1/exo1.c b/DEV1.1/CM1/exo1.c new file mode 100644 index 0000000..67fe02b --- /dev/null +++ b/DEV1.1/CM1/exo1.c @@ -0,0 +1,14 @@ +# include +# include + +int main(void) { + /* On peut écrire ces instructions en une seule ligne mais j'ai préféré + rappeler printf à chaque saut de ligne pour plus de lisibilité */ + printf(" __\n"); + printf("(___()'`;\n"); + printf("/, /`\n"); + printf("\\\\\"--\\\\\n"); + /* On doit utiliser un \ avant les \ et les " pour ne pas que le programme les voie comme des + instructions spécifiques ou un début/fin de chaîne de caractères */ + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/DEV1.1/CM1/exo2.c b/DEV1.1/CM1/exo2.c new file mode 100644 index 0000000..2d2719b --- /dev/null +++ b/DEV1.1/CM1/exo2.c @@ -0,0 +1,15 @@ +# include +# include + +int main(void) { + short int a = 7; + char b = 77; + double c = 777; + long int d = 7777; + + printf("%03hd\n", a); + printf("%c\n", b); + printf("%.0f\n", c); + printf("%lx\n", d); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/DEV1.1/CM1/exo3.c b/DEV1.1/CM1/exo3.c new file mode 100644 index 0000000..3cf44f8 --- /dev/null +++ b/DEV1.1/CM1/exo3.c @@ -0,0 +1,29 @@ +# include +# include + +int main(void) { + int lancer_1, lancer_2; + + printf("Entrez le premier dé : "); + scanf("%d", &lancer_1); + getchar(); /* Nécessaire pour retirer le \n stocké dans le tampon à l'instruction précédente */ + printf("Entrez le second dé : "); + scanf("%d", &lancer_2); + + if (lancer_1 == 1 && lancer_2 == 1) { + printf("Snake eyes"); + } + + else if (lancer_1 == 6 && lancer_2 == 6) { + printf("Boxcars"); + } + + else { + if (lancer_1 == lancer_2) { + printf("Hard ways"); + } + } + + putchar('\n'); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/DEV1.1/CM1/exo4.c b/DEV1.1/CM1/exo4.c new file mode 100644 index 0000000..1594a6a --- /dev/null +++ b/DEV1.1/CM1/exo4.c @@ -0,0 +1,28 @@ +# include +# include +# define NB_FACES 20 + +int main(void) { + int lancer_1, lancer_2; + /* Compte le diviseur de la future moyenne (ici 20*20), utile si jamais on modifie le nb de faces */ + int nb_combinaisons_possibles = 0; + int somme_meilleurs_lancers = 0; + + for (lancer_1 = 1; lancer_1 <= NB_FACES; lancer_1++) { + for (lancer_2 = 1; lancer_2 <= NB_FACES; lancer_2 ++) { + + if (lancer_1 >= lancer_2) { + somme_meilleurs_lancers += lancer_1; + } + + else { + somme_meilleurs_lancers += lancer_2; + } + + nb_combinaisons_possibles++; + } + } + + printf("Moyenne de tous les cas possibles pour %d faces : %d\n", NB_FACES, (somme_meilleurs_lancers / nb_combinaisons_possibles)); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/DEV1.1/CM1/exo5.c b/DEV1.1/CM1/exo5.c new file mode 100644 index 0000000..c6df449 --- /dev/null +++ b/DEV1.1/CM1/exo5.c @@ -0,0 +1,57 @@ +# include +# include +# define TAILLE_GRILLE 10 + + +int navires_encore_presents(int grille[][TAILLE_GRILLE], int len_grille) { + /* Renvoie 1 si des navires sont encore présents, faux sinon */ + int i; + int j; + for (i = 0; i != len_grille; i++) { + for (j = 0; j != len_grille; j++) { + if (grille[i][j] == 1) { + return 1; + } + } + } + return 0; +} + + +int main(void) { + /* Si un bateau est présent, la case vaut 1, sinon, elle vaut 0 */ + int grille[TAILLE_GRILLE][TAILLE_GRILLE] = { + {0,0,0,0,0,0,0,0,1,1}, + {0,1,0,0,0,0,0,0,0,0}, + {0,1,0,0,0,0,0,0,0,0}, + {0,1,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,0,0,0,0}, + {0,0,1,1,1,1,1,0,0,0}, + {0,1,1,1,1,0,0,0,0,1}, + {0,0,0,0,0,0,0,0,0,1}, + {0,0,0,0,0,0,0,0,0,1}, + }; + int tir_x, tir_y; + int nb_coups = 0; + + while (navires_encore_presents(grille, TAILLE_GRILLE) == 1) { + printf("Coordonnées ? "); + scanf("%d", &tir_x); + getchar(); + scanf("%d", &tir_y); + nb_coups++; + + if (grille[tir_x][tir_y] == 1) { + printf("Touché\n"); + grille[tir_x][tir_y] = 0; + } + + else { + printf("Dans l'eau\n"); + } + } + + printf("...\nPartie terminée en %d coups\n", nb_coups); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/DEV1.1/TP17/TP17_reponses.txt b/DEV1.1/TP17/TP17_reponses.txt new file mode 100644 index 0000000..4daf1d1 --- /dev/null +++ b/DEV1.1/TP17/TP17_reponses.txt @@ -0,0 +1,5 @@ +------ TP17 : Débogueur ------ + +1. On en déduit que la ligne qui a provoqué l'erreur est celle dans laquelle +se trouve le scanf. + diff --git a/DEV1.1/TP17/tests b/DEV1.1/TP17/tests new file mode 100755 index 0000000000000000000000000000000000000000..274ff635b783bd5d0d34357f7c6979b6ad7c4907 GIT binary patch literal 15504 zcmeHOYit}>6~4P}5|`HTCe*}9pdLyM392W4#dR8)tRL%)sq-Lpz(|DY*gLjIvUkny zZ0n@74GN&FOi)3n6x1J7szm=FD!~sVgydjI8q^<-cql@uYE@Kn1Qb^k>Fj9gXxEE*z18cO#?_3C*3{vn zCsp#Snj@X?6DqN$p5!`QJR#pZuu<5F-_|ww>EGP{$j*m{27mjtXUh%0EWcbuK6D(^ zCi#$%jy4gp$tJpYgT&dsj^ikF+B*8Xpj*%X@eTaQILV2YPzVR{h?f z)T-|f%5Ck+92h!cX6=GK?i5|SFm$AMGM}@DtdU6@t&UISbKJY>yRPe~6lNH+nZWG$ zScR+P>g8sKGD7-bppg0g&s3oTuq+zTp~Q4@AGr3%x$= z+eI(+xkJ95&K;U_krzUGJ_S6}LP#H8XV*gd@Oiix(r=N*3DbUsbbM*?6xAWUcRlvq z;(Z)}I0A75;t0eMh$9e3AdbL$6oJ3i-uVyX+@GqA*-aPsDP??R&P`SpjB~%Jp7%yj z+5ao3D~&H=U)zvIiRu$%yS`X~H2$3G^k{i~0aa?R<!hCBJz__&c8e z{t<$`H;wYLaq+c7#>JH?BXP;NdeglF4g6F08>p@@!*^r`b8zu?yOLnrh6dL0ik_OZW<=J!F+!tugyP1S_$->L7iarEf#a zf2mX+1ZvB8jRo#}y;3<3Yyv(9B%yDdB#AR8RAMHT*nRt!>L>7P0qN=6{sP+gC^__P z@xEl;jbb~t^U%}xRkbzMzqS68wYNQ7eO4XXb@1bDcYB`+iTgQhW%TX!(Y-bG)nsqY z=40ppda{2J+oQ050jR{Dob(+?7fT$0I0A75;t0eMh$9e3AdWyBfj9zj1pbF3AbEn4 z7brP@oqSBU%dv6ZAd(V2S>XJ_ol@sK!`)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K^^1md W#Fj`EG3SK55S2O@+>Rs9ROX~WF` literal 0 HcmV?d00001 diff --git a/DEV1.1/TP17/tests.c b/DEV1.1/TP17/tests.c new file mode 100644 index 0000000..697856c --- /dev/null +++ b/DEV1.1/TP17/tests.c @@ -0,0 +1,16 @@ +#include +#include + +int somme(int n, int m) { + return *n+*m; +} + +int main(void) { + int valeur; + int* p = NULL; + printf("Entrez un entier : "); + scanf("%d", p); + + printf("Le double vaut %d\n", somme(*p, *p)); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/DEV1.1/TP19/TP19_reponses.txt b/DEV1.1/TP19/TP19_reponses.txt new file mode 100644 index 0000000..cd2d54a --- /dev/null +++ b/DEV1.1/TP19/TP19_reponses.txt @@ -0,0 +1,4 @@ +------- TP19 : Allocation dynamique -------- + +1. + diff --git a/DEV1.1/TP19/tests.c b/DEV1.1/TP19/tests.c new file mode 100644 index 0000000..89a8b4b --- /dev/null +++ b/DEV1.1/TP19/tests.c @@ -0,0 +1,34 @@ +# include +# include + +int main(void) { + int taille_tab; + double* tab = (double*) malloc(3*sizeof(double)); + int i; + int j; + printf("Combien de réels souhaitez-vous entrer ? "); + scanf("%d", &taille_tab); + getchar(); + tab = (double*) realloc(tab, taille_tab*sizeof(double)); + for (i = 0; i != taille_tab; i++) { + printf("Entrez le %de réel : ", i + 1); + scanf("%lf", &tab[i]); + getchar(); + } + + for (i = 0; i != (taille_tab - 1); i++) { + for (j = i; j != taille_tab; j++) { + if (tab[i] == tab[j]) { + tab[j] = 0.0; + } + } + } + + for (i = 0; i != taille_tab; i++) { + if (tab[i] != 0.0) { + printf("%.3f ", tab[i]); + } + } + putchar('\n'); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/DEV1.1/simoes_CM1.tar.gz b/DEV1.1/simoes_CM1.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..ddc0f8a621aa6485be648a95ffeaa5f8e21dd809 GIT binary patch literal 1490 zcmV;@1ugm?iwFP!000001MOICZ`(Ey&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