Fin du tp
This commit is contained in:
parent
841c8eeab1
commit
161df92584
14
DEV1.1/CM1/exo1.c
Normal file
14
DEV1.1/CM1/exo1.c
Normal file
@ -0,0 +1,14 @@
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
15
DEV1.1/CM1/exo2.c
Normal file
15
DEV1.1/CM1/exo2.c
Normal file
@ -0,0 +1,15 @@
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
29
DEV1.1/CM1/exo3.c
Normal file
29
DEV1.1/CM1/exo3.c
Normal file
@ -0,0 +1,29 @@
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
28
DEV1.1/CM1/exo4.c
Normal file
28
DEV1.1/CM1/exo4.c
Normal file
@ -0,0 +1,28 @@
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# 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;
|
||||
}
|
57
DEV1.1/CM1/exo5.c
Normal file
57
DEV1.1/CM1/exo5.c
Normal file
@ -0,0 +1,57 @@
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# 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;
|
||||
}
|
5
DEV1.1/TP17/TP17_reponses.txt
Normal file
5
DEV1.1/TP17/TP17_reponses.txt
Normal file
@ -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.
|
||||
|
BIN
DEV1.1/TP17/tests
Executable file
BIN
DEV1.1/TP17/tests
Executable file
Binary file not shown.
16
DEV1.1/TP17/tests.c
Normal file
16
DEV1.1/TP17/tests.c
Normal file
@ -0,0 +1,16 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
4
DEV1.1/TP19/TP19_reponses.txt
Normal file
4
DEV1.1/TP19/TP19_reponses.txt
Normal file
@ -0,0 +1,4 @@
|
||||
------- TP19 : Allocation dynamique --------
|
||||
|
||||
1.
|
||||
|
34
DEV1.1/TP19/tests.c
Normal file
34
DEV1.1/TP19/tests.c
Normal file
@ -0,0 +1,34 @@
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
BIN
DEV1.1/simoes_CM1.tar.gz
Normal file
BIN
DEV1.1/simoes_CM1.tar.gz
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user