Compare commits
28 Commits
471e4a7e75
...
main
Author | SHA1 | Date | |
---|---|---|---|
|
2c3e150ec5 | ||
|
c16ef0985f | ||
|
2f94e24111 | ||
|
fe693705bf | ||
|
376861b608 | ||
|
42cc204dea | ||
|
6f2ea4a30a | ||
9d03079b51 | |||
4485b2722e | |||
|
cf33623a5d | ||
|
2a0aa37baa | ||
|
9441c8978a | ||
|
422a41d232 | ||
|
3891eea685 | ||
|
080e0022b8 | ||
|
dd8ce34656 | ||
|
dd0903e9fc | ||
|
209f320a5a | ||
|
2217e7986c | ||
|
59f7eead89 | ||
|
f7764aa296 | ||
|
6f3e79de9d | ||
|
161df92584 | ||
|
841c8eeab1 | ||
|
a379ee9e1f | ||
|
f4b9936c0c | ||
|
af0a212997 | ||
|
7d319d2d6a |
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;
|
||||||
|
}
|
24
DEV1.1/CM2/Makefile
Normal file
24
DEV1.1/CM2/Makefile
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
CC = gcc
|
||||||
|
CFLAGS = -ansi \
|
||||||
|
-pedantic
|
||||||
|
EXE = final
|
||||||
|
OFILES = moyenne.o \
|
||||||
|
moyenne_main.o
|
||||||
|
|
||||||
|
### BUT PAR DEFAUT ###
|
||||||
|
|
||||||
|
final : ${EXE}
|
||||||
|
|
||||||
|
### REGLES ESSENTIELLES ###
|
||||||
|
|
||||||
|
moyenne_main.o : moyenne_main.c
|
||||||
|
|
||||||
|
moyenne.o : moyenne.h moyenne.c
|
||||||
|
|
||||||
|
${EXE} : ${OFILES}
|
||||||
|
$(CC) $(CFLAGS) -o ${EXE} ${OFILES}
|
||||||
|
|
||||||
|
### REGLES OPTIONNELLES ###
|
||||||
|
|
||||||
|
clean :
|
||||||
|
-rm -f ${OFILES} ${EXE}
|
23
DEV1.1/CM2/melange.c
Normal file
23
DEV1.1/CM2/melange.c
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# include <stdio.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
FILE* fichier = NULL;
|
||||||
|
char premier_octet;
|
||||||
|
char resultat;
|
||||||
|
if (argc != 2) {
|
||||||
|
printf("Pas de fichier à modifier.\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
fichier = fopen(argv[1], "r");
|
||||||
|
if (fichier == NULL) {
|
||||||
|
printf("Erreur d'ouverture.\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
fread(&premier_octet, 1, 1, fichier);
|
||||||
|
fclose(fichier);
|
||||||
|
fichier = fopen(argv[1], "a+");
|
||||||
|
/* Pas fini */
|
||||||
|
fclose(fichier);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
10
DEV1.1/CM2/mesure.c
Normal file
10
DEV1.1/CM2/mesure.c
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# include <stdio.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
# include <sys/stat.h>
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
struct stat a;
|
||||||
|
stat(argv[1], &a);
|
||||||
|
printf("%jd octets\n", a.st_size);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
69
DEV1.1/CM2/moderation.c
Normal file
69
DEV1.1/CM2/moderation.c
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
# include <stdio.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
|
||||||
|
struct mail {
|
||||||
|
double x;
|
||||||
|
double y;
|
||||||
|
struct mail* suivant;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct mail maillon;
|
||||||
|
|
||||||
|
void afficher_liste(maillon* liste) {
|
||||||
|
maillon* p;
|
||||||
|
for (p = liste; p != NULL; p = p->suivant) {
|
||||||
|
printf("(%.1f, %.1f) -> ", p->x, p->y);
|
||||||
|
}
|
||||||
|
putchar('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
maillon* creation_liste(void) {
|
||||||
|
int i;
|
||||||
|
maillon* p;
|
||||||
|
maillon* premier;
|
||||||
|
maillon* s;
|
||||||
|
srand(time(NULL));
|
||||||
|
premier = (maillon*) malloc(sizeof(maillon));
|
||||||
|
if (!premier) {
|
||||||
|
printf("Erreur d'allocation mémoire. (1) \n");
|
||||||
|
}
|
||||||
|
premier->x = -12; /* Le premier maillon sera toujours négatif, les autres seront aléatoires */
|
||||||
|
premier->y = -3;
|
||||||
|
p = premier;
|
||||||
|
for (i = 0; i != 4; i++) {
|
||||||
|
s = (maillon*) malloc(sizeof(maillon));
|
||||||
|
if (!s) {
|
||||||
|
printf("Erreur d'allocation mémoire. (2) \n");
|
||||||
|
}
|
||||||
|
s->x = (rand() % 50) - 25;
|
||||||
|
s->y = (rand() % 50) - 25;
|
||||||
|
p->suivant = s;
|
||||||
|
p = s;
|
||||||
|
}
|
||||||
|
return premier;
|
||||||
|
}
|
||||||
|
|
||||||
|
maillon* supprime_coord_negatives(maillon* liste) {
|
||||||
|
maillon* p;
|
||||||
|
maillon* premier = liste;
|
||||||
|
maillon* precedent = liste;
|
||||||
|
for (p = liste; p != NULL; p = p->suivant) {
|
||||||
|
if ((p->x) < 0.0 && (p->y) < 0.0) {
|
||||||
|
p = precedent;
|
||||||
|
p->suivant = p->suivant->suivant;
|
||||||
|
precedent = p;
|
||||||
|
p = p->suivant;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
precedent = p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return premier;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
maillon* liste = creation_liste();
|
||||||
|
afficher_liste(liste);
|
||||||
|
afficher_liste(supprime_coord_negatives(liste));
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
8
DEV1.1/CM2/moyenne.c
Normal file
8
DEV1.1/CM2/moyenne.c
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
double moyenne(int* t, int len) {
|
||||||
|
int i;
|
||||||
|
int somme = 0;
|
||||||
|
for (i = 0; i != len; i++) {
|
||||||
|
somme += t[i];
|
||||||
|
}
|
||||||
|
return somme/len;
|
||||||
|
}
|
6
DEV1.1/CM2/moyenne.h
Normal file
6
DEV1.1/CM2/moyenne.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#ifndef MOYENNE
|
||||||
|
#define MOYENNE
|
||||||
|
|
||||||
|
double moyenne(int* t, int len);
|
||||||
|
|
||||||
|
#endif
|
14
DEV1.1/CM2/moyenne_main.c
Normal file
14
DEV1.1/CM2/moyenne_main.c
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# include <stdio.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
# include "moyenne.h"
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
int i;
|
||||||
|
int* t = malloc(sizeof(int)*argc);
|
||||||
|
for (i = 0; i != argc-1; i++) {
|
||||||
|
t[i] = (int) strtol(argv[i+1], NULL, 10);
|
||||||
|
}
|
||||||
|
printf("Moyenne : %.2f\n", moyenne(t, argc-1));
|
||||||
|
free(t);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
6
DEV1.1/CM2/toto.c
Normal file
6
DEV1.1/CM2/toto.c
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# include <stdio.h>
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
printf("Hello world\n");
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
24
DEV1.1/CM3/Makefile
Normal file
24
DEV1.1/CM3/Makefile
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
CC = gcc
|
||||||
|
CFLAGS = -ansi \
|
||||||
|
-pedantic
|
||||||
|
EXE = final
|
||||||
|
OFILES = queue.o \
|
||||||
|
bifurcation.o
|
||||||
|
|
||||||
|
### BUT PAR DEFAUT ###
|
||||||
|
|
||||||
|
final : ${EXE}
|
||||||
|
|
||||||
|
### REGLES ESSENTIELLES ###
|
||||||
|
|
||||||
|
bifuraction.o : bifurcation.c
|
||||||
|
|
||||||
|
queue.o : queue.h queue.c
|
||||||
|
|
||||||
|
${EXE} : ${OFILES}
|
||||||
|
$(CC) $(CFLAGS) -o ${EXE} ${OFILES}
|
||||||
|
|
||||||
|
### REGLES OPTIONNELLES ###
|
||||||
|
|
||||||
|
clean :
|
||||||
|
-rm -f ${OFILES} ${EXE}
|
37
DEV1.1/CM3/bifurcation.c
Normal file
37
DEV1.1/CM3/bifurcation.c
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "queue.h"
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
queue file = create_queue();
|
||||||
|
int somme = 0;
|
||||||
|
int i;
|
||||||
|
if (argc < 2) {
|
||||||
|
printf("Rien n'a été écrit en ligne de commande.\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i != argc; i++) {
|
||||||
|
int valeur = atoi(argv[i]);
|
||||||
|
if (valeur == 0) {
|
||||||
|
/* Rien */
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
somme += valeur;
|
||||||
|
/* Etant donné que la file doit stocker des long et ne peut pas stocker des char*,
|
||||||
|
je stocke les BONNES valeurs dans la liste pour afficher plus tard celles qui n'en font pas partie */
|
||||||
|
enqueue(file, strtol(argv[i], NULL, 10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("somme : %d\n", somme);
|
||||||
|
printf("ignorés : ");
|
||||||
|
while (!empty(file)) {
|
||||||
|
printf("%c", (char) dequeue(file));
|
||||||
|
putchar(' ');
|
||||||
|
}
|
||||||
|
destroy_queue(file);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
26
DEV1.1/CM3/bilan.c
Normal file
26
DEV1.1/CM3/bilan.c
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
int nb_negatifs(int* tab, size_t taille_tab) {
|
||||||
|
if (taille_tab == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return (tab[taille_tab-1] < 0) + nb_negatifs(tab, taille_tab-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
int tab_1[5]; /* Vide */
|
||||||
|
int tab_2[5] = {2, 4, 1, 38, 0}; /* Positif ou nul */
|
||||||
|
int tab_3[5] = {-2, -7, -20, -829, -1000}; /* Strictement négatif */
|
||||||
|
int tab_4[5] = {3, -7, 11, 0, -50}; /* Signe divers et au moins une valeur nulle */
|
||||||
|
|
||||||
|
printf("%d\n", nb_negatifs(tab_1, 5));
|
||||||
|
printf("%d\n", nb_negatifs(tab_2, 5));
|
||||||
|
printf("%d\n", nb_negatifs(tab_3, 5));
|
||||||
|
printf("%d\n", nb_negatifs(tab_4, 5));
|
||||||
|
|
||||||
|
for
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
13
DEV1.1/CM3/blague.c
Normal file
13
DEV1.1/CM3/blague.c
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#include<stdlib.h>
|
||||||
|
#include<stdio.h>
|
||||||
|
#include<time.h>
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
srand(time(NULL));
|
||||||
|
if (rand()%2) {
|
||||||
|
printf("Ϳоie !\n");
|
||||||
|
} else {
|
||||||
|
printf("Désespoir !\n");
|
||||||
|
}
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
77
DEV1.1/CM3/blague_resolu.c
Normal file
77
DEV1.1/CM3/blague_resolu.c
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char valeurs[1000];
|
||||||
|
int debut;
|
||||||
|
int fin;
|
||||||
|
size_t taille;
|
||||||
|
} file;
|
||||||
|
|
||||||
|
void initialise_file(file* f) {
|
||||||
|
f->debut = 0;
|
||||||
|
f->fin = 0;
|
||||||
|
f->taille = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int empty(file* f) {
|
||||||
|
return (f->taille == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void enqueue(file* f, char c) {
|
||||||
|
f->valeurs[f->fin] = c;
|
||||||
|
f->fin++;
|
||||||
|
f->taille++;
|
||||||
|
}
|
||||||
|
|
||||||
|
char dequeue(file* f) {
|
||||||
|
if (empty(f)) {
|
||||||
|
printf("Erreur : La file est vide.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
f->debut++;
|
||||||
|
f->taille--;
|
||||||
|
return f->valeurs[f->debut-1];
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
FILE* fichier = NULL;
|
||||||
|
file f;
|
||||||
|
char resultat;
|
||||||
|
initialise_file(&f);
|
||||||
|
if (argc != 2) {
|
||||||
|
printf("Il faut entrer un (unique) chemin de fichier.\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
fichier = fopen(argv[1], "r");
|
||||||
|
if (fichier == NULL) {
|
||||||
|
printf("Erreur d'ouverture.\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
fread(&resultat, 1, 1, fichier);
|
||||||
|
if (resultat == ';') { /* Point d'interrogation grec */
|
||||||
|
enqueue(&f, ';'); /* Point virgule */
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
enqueue(&f, resultat);
|
||||||
|
}
|
||||||
|
while (feof(fichier) != 0) {
|
||||||
|
fread(&resultat, 1, 1, fichier);
|
||||||
|
if (resultat == ';') { /* Point d'interrogation grec */
|
||||||
|
enqueue(&f, ';'); /* Point virgule */
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
enqueue(&f, resultat);
|
||||||
|
}
|
||||||
|
fclose(fichier);
|
||||||
|
|
||||||
|
fichier = fopen(fichier, "w+");
|
||||||
|
while (feof(fichier) != 0) {
|
||||||
|
resultat = dequeue(&f);
|
||||||
|
fwrite(&resultat, 1, 1, fichier);
|
||||||
|
}
|
||||||
|
fclose(fichier);
|
||||||
|
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
69
DEV1.1/CM3/queue.c
Normal file
69
DEV1.1/CM3/queue.c
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include "queue.h"
|
||||||
|
|
||||||
|
struct s_link {
|
||||||
|
unsigned value;
|
||||||
|
struct s_link *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct s_link link;
|
||||||
|
|
||||||
|
struct s_queue {
|
||||||
|
link *first; /* sortie */
|
||||||
|
link *last; /* entrée */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* crée une file vide */
|
||||||
|
queue create_queue(void) {
|
||||||
|
return (queue) calloc(1, sizeof(struct s_queue));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ajoute un élément à la file. Renvoie 0 en cas d'échec */
|
||||||
|
int enqueue(queue the_queue, unsigned the_value) {
|
||||||
|
link *new = (link*) malloc(sizeof(link));
|
||||||
|
if (new == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
new->value = the_value;
|
||||||
|
new->next = NULL;
|
||||||
|
if (the_queue->last == NULL) {
|
||||||
|
the_queue->first = new;
|
||||||
|
} else {
|
||||||
|
the_queue->last->next = new;
|
||||||
|
}
|
||||||
|
the_queue->last = new;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* renvoie 1 si la file est vide */
|
||||||
|
int empty(queue the_queue) {
|
||||||
|
return the_queue->first == NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* retire un élément de la file. Renvoie l'élément retiré, ou -1 en cas d'échec */
|
||||||
|
long dequeue(queue the_queue) {
|
||||||
|
if(the_queue->first == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
link l = *(the_queue->first);
|
||||||
|
free(the_queue->first);
|
||||||
|
the_queue->first = l.next;
|
||||||
|
if (the_queue->first == NULL) {
|
||||||
|
the_queue->last = NULL;
|
||||||
|
}
|
||||||
|
return l.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* détruit une file en libérant les ressources associées */
|
||||||
|
void destroy_queue(queue the_queue) {
|
||||||
|
link *current, *saved;
|
||||||
|
|
||||||
|
current = the_queue->first;
|
||||||
|
while(current != NULL) {
|
||||||
|
saved = current->next;
|
||||||
|
free(current);
|
||||||
|
current = saved;
|
||||||
|
}
|
||||||
|
free(the_queue);
|
||||||
|
}
|
22
DEV1.1/CM3/queue.h
Normal file
22
DEV1.1/CM3/queue.h
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#ifndef QUEUE_H
|
||||||
|
#define QUEUE_H
|
||||||
|
|
||||||
|
/* le type queue représente une file */
|
||||||
|
typedef struct s_queue *queue;
|
||||||
|
|
||||||
|
/* crée une file vide. Renvoie NULL en cas d'échec */
|
||||||
|
queue create_queue(void);
|
||||||
|
|
||||||
|
/* ajoute un élément à la file. Renvoie 0 en cas d'échec */
|
||||||
|
int enqueue(queue, unsigned);
|
||||||
|
|
||||||
|
/* renvoie 1 si la file est vide */
|
||||||
|
int empty(queue);
|
||||||
|
|
||||||
|
/* retire un élément de la file. Renvoie l'élément retiré, ou -1 en cas d'échec */
|
||||||
|
long dequeue(queue);
|
||||||
|
|
||||||
|
/* détruit une file en libérant les ressources associées */
|
||||||
|
void destroy_queue(queue);
|
||||||
|
|
||||||
|
#endif /* QUEUE_H */
|
10
DEV1.1/Entrainements/controle_machine_2_A/Makefile
Normal file
10
DEV1.1/Entrainements/controle_machine_2_A/Makefile
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
complet : carre.o lightness.o
|
||||||
|
gcc -ansi -pedantic -o carre.o lightness.o
|
||||||
|
carre.o : carre.c
|
||||||
|
gcc -ansi -pedantic -c carre.c
|
||||||
|
lightness.o : lightness.c lightness.h
|
||||||
|
gcc -ansi -pedantic -c lightness.c
|
||||||
|
clean :
|
||||||
|
rm -f carre.o lightness.o
|
||||||
|
run : complet
|
||||||
|
./complet
|
50
DEV1.1/Entrainements/controle_machine_2_A/carre.c
Normal file
50
DEV1.1/Entrainements/controle_machine_2_A/carre.c
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#include<stdlib.h>
|
||||||
|
#include<stdio.h>
|
||||||
|
#include<time.h>
|
||||||
|
#include"lightness.h"
|
||||||
|
|
||||||
|
#define LIGHT 0
|
||||||
|
#define DARK 1
|
||||||
|
#define RED 1
|
||||||
|
#define GREEN 2
|
||||||
|
#define BLUE 4
|
||||||
|
#define LIGHT_RED 217
|
||||||
|
#define DARK_RED 124
|
||||||
|
#define LIGHT_GREEN 157
|
||||||
|
#define DARK_GREEN 34
|
||||||
|
#define LIGHT_BLUE 147
|
||||||
|
#define DARK_BLUE 19
|
||||||
|
|
||||||
|
int hue(void) {
|
||||||
|
int choice = rand()%3;
|
||||||
|
if (choice == 0) {
|
||||||
|
return RED;
|
||||||
|
} else if (choice == 1) {
|
||||||
|
return GREEN;
|
||||||
|
} else /* if (choice == 2) */ {
|
||||||
|
return BLUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
int l, c, v;
|
||||||
|
|
||||||
|
srand(time(NULL));
|
||||||
|
l = lightness();
|
||||||
|
c = hue();
|
||||||
|
|
||||||
|
if (c == RED) {
|
||||||
|
v = (l == LIGHT) ? LIGHT_RED : DARK_RED;
|
||||||
|
} else if (c == GREEN) {
|
||||||
|
v = (l == LIGHT) ? LIGHT_GREEN : DARK_GREEN;
|
||||||
|
} else /* if (c == BLUE) */ {
|
||||||
|
v = (l == LIGHT) ? LIGHT_BLUE : DARK_BLUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("┏━━━━┓\n");
|
||||||
|
printf("┃\33[48;5;%dm \33[m┃\n", v);
|
||||||
|
printf("┃\33[48;5;%dm \33[m┃\n", v);
|
||||||
|
printf("┗━━━━┛\n");
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
9
DEV1.1/Entrainements/controle_machine_2_A/ldiv.c
Normal file
9
DEV1.1/Entrainements/controle_machine_2_A/ldiv.c
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# include <stdio.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
ldiv_t quotient = ldiv(strtol(argv[1], NULL, 10), strtol(argv[2], NULL, 10));
|
||||||
|
printf("quotient : %ld\n", quotient.quot);
|
||||||
|
printf("reste : %ld\n", quotient.rem);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
12
DEV1.1/Entrainements/controle_machine_2_A/lightness.c
Normal file
12
DEV1.1/Entrainements/controle_machine_2_A/lightness.c
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#include<stdlib.h>
|
||||||
|
#include<stdio.h>
|
||||||
|
#include<time.h>
|
||||||
|
#include "carre.h"
|
||||||
|
|
||||||
|
int lightness(void) {
|
||||||
|
if (time(NULL)%2) {
|
||||||
|
return LIGHT;
|
||||||
|
} else {
|
||||||
|
return DARK;
|
||||||
|
}
|
||||||
|
}
|
6
DEV1.1/Entrainements/controle_machine_2_A/lightness.h
Normal file
6
DEV1.1/Entrainements/controle_machine_2_A/lightness.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#ifndef LIGHTNESS_H
|
||||||
|
#define LIGHTNESS_H
|
||||||
|
|
||||||
|
int lightness(void);
|
||||||
|
|
||||||
|
#endif
|
BIN
DEV1.1/Entrainements/controle_machine_2_A/reitne
Normal file
BIN
DEV1.1/Entrainements/controle_machine_2_A/reitne
Normal file
Binary file not shown.
39
DEV1.1/Entrainements/controle_machine_2_A/suite.c
Normal file
39
DEV1.1/Entrainements/controle_machine_2_A/suite.c
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
# include <stdio.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
int* suite(int n) {
|
||||||
|
int* p = NULL;
|
||||||
|
int compteur = 0;
|
||||||
|
p = (int*) malloc(sizeof(int));
|
||||||
|
if (p) {
|
||||||
|
p[0] = n;
|
||||||
|
while (!n%2) {
|
||||||
|
compteur++;
|
||||||
|
p = (int*) realloc(p, sizeof(int));
|
||||||
|
n = n/2;
|
||||||
|
p[compteur] = n;
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("Espace mémoire insuffisant.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void afficher_tableau(int* t) {
|
||||||
|
int i;
|
||||||
|
size_t max = *(&t + 1) - t;
|
||||||
|
printf("%lu", max);
|
||||||
|
for (i = 0; i != max ; i++) {
|
||||||
|
printf("| %d", t[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
int tab[5] = {2, 5, 8, 9, 1};
|
||||||
|
afficher_tableau(tab);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
27
DEV1.1/Entrainements/controle_machine_2_B/Makefile
Normal file
27
DEV1.1/Entrainements/controle_machine_2_B/Makefile
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
CC = gcc
|
||||||
|
CFLAGS = -ansi \
|
||||||
|
-pedantic
|
||||||
|
EXE = but
|
||||||
|
OFILES = carre.o \
|
||||||
|
hue.o
|
||||||
|
|
||||||
|
### BUT PAR DEFAUT ###
|
||||||
|
|
||||||
|
but : ${EXE}
|
||||||
|
|
||||||
|
### REGLES ESSENTIELLES ###
|
||||||
|
|
||||||
|
carre.o : carre.c
|
||||||
|
|
||||||
|
hue.o : hue.h hue.c
|
||||||
|
|
||||||
|
${EXE} : ${OFILES}
|
||||||
|
$(CC) $(CFLAGS) -o ${EXE} ${OFILES}
|
||||||
|
|
||||||
|
### REGLES OPTIONNELLES ###
|
||||||
|
|
||||||
|
run : but
|
||||||
|
./${EXE}
|
||||||
|
|
||||||
|
clean :
|
||||||
|
-rm -f ${OFILES} ${EXE}
|
BIN
DEV1.1/Entrainements/controle_machine_2_B/but
Executable file
BIN
DEV1.1/Entrainements/controle_machine_2_B/but
Executable file
Binary file not shown.
48
DEV1.1/Entrainements/controle_machine_2_B/carre.c
Normal file
48
DEV1.1/Entrainements/controle_machine_2_B/carre.c
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
#include<stdlib.h>
|
||||||
|
#include<stdio.h>
|
||||||
|
#include<time.h>
|
||||||
|
#include "hue.h"
|
||||||
|
|
||||||
|
#define LIGHT 0
|
||||||
|
#define DARK 1
|
||||||
|
#define RED 1
|
||||||
|
#define GREEN 2
|
||||||
|
#define BLUE 4
|
||||||
|
#define LIGHT_RED 217
|
||||||
|
#define DARK_RED 124
|
||||||
|
#define LIGHT_GREEN 157
|
||||||
|
#define DARK_GREEN 34
|
||||||
|
#define LIGHT_BLUE 147
|
||||||
|
#define DARK_BLUE 19
|
||||||
|
|
||||||
|
int lightness(void) {
|
||||||
|
if (time(NULL)%2) {
|
||||||
|
return LIGHT;
|
||||||
|
} else {
|
||||||
|
return DARK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
int l, c, v;
|
||||||
|
|
||||||
|
srand(time(NULL));
|
||||||
|
l = lightness();
|
||||||
|
c = hue();
|
||||||
|
|
||||||
|
if (c == RED) {
|
||||||
|
v = (l == LIGHT) ? LIGHT_RED : DARK_RED;
|
||||||
|
} else if (c == GREEN) {
|
||||||
|
v = (l == LIGHT) ? LIGHT_GREEN : DARK_GREEN;
|
||||||
|
} else /* if (c == BLUE) */ {
|
||||||
|
v = (l == LIGHT) ? LIGHT_BLUE : DARK_BLUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("┏━━━━┓\n");
|
||||||
|
printf("┃\33[48;5;%dm \33[m┃\n", v);
|
||||||
|
printf("┃\33[48;5;%dm \33[m┃\n", v);
|
||||||
|
printf("┗━━━━┛\n");
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
11
DEV1.1/Entrainements/controle_machine_2_B/decomposition.c
Normal file
11
DEV1.1/Entrainements/controle_machine_2_B/decomposition.c
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# include <stdio.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
# include <math.h>
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
double partie_entiere;
|
||||||
|
modf(strtod(argv[1], NULL), &partie_entiere);
|
||||||
|
printf("partie entière : %f\npartie décimale : %f\n", partie_entiere, (strtod(argv[1],NULL) - partie_entiere));
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
14
DEV1.1/Entrainements/controle_machine_2_B/hue.c
Normal file
14
DEV1.1/Entrainements/controle_machine_2_B/hue.c
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#define RED 1
|
||||||
|
#define GREEN 2
|
||||||
|
#define BLUE 4
|
||||||
|
|
||||||
|
int hue(void) {
|
||||||
|
int choice = rand()%3;
|
||||||
|
if (choice == 0) {
|
||||||
|
return RED;
|
||||||
|
} else if (choice == 1) {
|
||||||
|
return GREEN;
|
||||||
|
} else /* if (choice == 2) */ {
|
||||||
|
return BLUE;
|
||||||
|
}
|
||||||
|
}
|
6
DEV1.1/Entrainements/controle_machine_2_B/hue.h
Normal file
6
DEV1.1/Entrainements/controle_machine_2_B/hue.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#ifndef HUE
|
||||||
|
#define HUE
|
||||||
|
|
||||||
|
int hue(void);
|
||||||
|
|
||||||
|
#endif
|
7
DEV1.1/Entrainements/controle_machine_A/chouette.c
Normal file
7
DEV1.1/Entrainements/controle_machine_A/chouette.c
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# include <stdio.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
printf("{o,o}\n(__(\\n-\"-\"-\n");
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
19
DEV1.1/Entrainements/controle_machine_A/cible.c
Normal file
19
DEV1.1/Entrainements/controle_machine_A/cible.c
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# include <stdio.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
char lettre;
|
||||||
|
char debut;
|
||||||
|
printf("Entrez une minuscule : ");
|
||||||
|
scanf("%c", &lettre);
|
||||||
|
for (debut = 'a'; debut != lettre; debut++) {
|
||||||
|
putchar(debut);
|
||||||
|
}
|
||||||
|
printf("[%c]", lettre);
|
||||||
|
lettre++;
|
||||||
|
for (debut = ('z' + 1); debut != lettre; lettre++) {
|
||||||
|
putchar(lettre);
|
||||||
|
}
|
||||||
|
putchar('\n');
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
28
DEV1.1/Entrainements/controle_machine_A/coincidences.c
Normal file
28
DEV1.1/Entrainements/controle_machine_A/coincidences.c
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# include <stdio.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
int resultats[5];
|
||||||
|
int i;
|
||||||
|
int max;
|
||||||
|
int compteur_occurences;
|
||||||
|
for (i = 0; i != 5; i++) {
|
||||||
|
printf("Jet n°%d : ", i+1);
|
||||||
|
scanf("%d", &resultats[i]);
|
||||||
|
getchar();
|
||||||
|
}
|
||||||
|
max = resultats[0];
|
||||||
|
for (i = 0; i != 5; i++) {
|
||||||
|
if (resultats[i] > max) {
|
||||||
|
max = resultats[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
compteur_occurences = 0;
|
||||||
|
for (i = 0; i != 5; i++) {
|
||||||
|
if (max == resultats[i]) {
|
||||||
|
compteur_occurences++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("Occurences maximum : %d\n", compteur_occurences);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
19
DEV1.1/Entrainements/controle_machine_A/conversion.c
Normal file
19
DEV1.1/Entrainements/controle_machine_A/conversion.c
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
double pouce, pied;
|
||||||
|
double taille_utilisateur;
|
||||||
|
int nb_pieds, nb_pouces;
|
||||||
|
int i;
|
||||||
|
nb_pieds, nb_pouces = 0;
|
||||||
|
pouce = 0.0256; /* Valeur donnée en m */
|
||||||
|
pied = pouce * 12;
|
||||||
|
printf("Entrez votre taille : ");
|
||||||
|
scanf("%lf", &taille_utilisateur);
|
||||||
|
for (;taille_utilisateur > 0; (taille_utilisateur - 0.25)){
|
||||||
|
nb_pieds++;
|
||||||
|
printf("%f",taille_utilisateur);
|
||||||
|
}
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
@@ -0,0 +1,9 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
printf("%d\n", 58);
|
||||||
|
printf("%o\n", 05); /* Littéralement impossible */
|
||||||
|
printf("%x\n", 0x58);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
0
DEV1.1/Entrainements/controle_machine_A/test.py
Normal file
0
DEV1.1/Entrainements/controle_machine_A/test.py
Normal file
53
DEV1.1/Entrainements/controle_machine_B/canettes.c
Normal file
53
DEV1.1/Entrainements/controle_machine_B/canettes.c
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
# define CANETTE 0.6
|
||||||
|
# define PACK 3.39
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
double budget;
|
||||||
|
double i;
|
||||||
|
int nb_packs, nb_canettes;
|
||||||
|
nb_packs = 0;
|
||||||
|
nb_canettes = 0;
|
||||||
|
printf("Quel est votre budget ? ");
|
||||||
|
scanf("%lf", &budget);
|
||||||
|
for (i = budget; i > PACK; i -= PACK) {
|
||||||
|
nb_packs++;
|
||||||
|
}
|
||||||
|
budget -= (nb_packs * PACK);
|
||||||
|
for (i = budget; i > CANETTE; i -= CANETTE) {
|
||||||
|
nb_canettes++;
|
||||||
|
}
|
||||||
|
if (nb_packs > 0 && nb_canettes > 0) {
|
||||||
|
if (nb_packs == 1) {
|
||||||
|
printf("1 pack et ");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("%d packs et ", nb_packs);
|
||||||
|
}
|
||||||
|
if (nb_canettes == 1) {
|
||||||
|
printf("1 unité");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("%d unités", nb_canettes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (nb_packs > 0) {
|
||||||
|
if (nb_packs == 1){
|
||||||
|
printf("1 pack");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("%d packs", nb_packs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (nb_canettes == 1) {
|
||||||
|
printf("1 unité");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("%d unités", nb_canettes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
7
DEV1.1/Entrainements/controle_machine_B/chauve_souris.c
Normal file
7
DEV1.1/Entrainements/controle_machine_B/chauve_souris.c
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# include <stdio.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
|
||||||
|
int main(void){
|
||||||
|
printf(" _ ,_, _\n / `'=) (='` \\\n/.-.-.\\/.-.-.\\\n` \" `\n");
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
23
DEV1.1/Entrainements/controle_machine_B/circulation.c
Normal file
23
DEV1.1/Entrainements/controle_machine_B/circulation.c
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# include <stdio.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
char lettre;
|
||||||
|
char fin = 'z';
|
||||||
|
char temp;
|
||||||
|
printf("Entrez une minuscule : ");
|
||||||
|
scanf("%c", &lettre);
|
||||||
|
temp = lettre;
|
||||||
|
while (lettre != fin) {
|
||||||
|
putchar(lettre);
|
||||||
|
lettre++;
|
||||||
|
}
|
||||||
|
putchar('z');
|
||||||
|
fin -= 25;
|
||||||
|
while (fin != temp) {
|
||||||
|
putchar(fin);
|
||||||
|
fin++;
|
||||||
|
}
|
||||||
|
putchar('\n');
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
38
DEV1.1/Entrainements/controle_machine_B/coincidences.c
Normal file
38
DEV1.1/Entrainements/controle_machine_B/coincidences.c
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
# include <stdio.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
int resultats[5];
|
||||||
|
int tab_trie[5];
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
int min;
|
||||||
|
int temp;
|
||||||
|
int suite_1[5] = {1, 2, 3, 4, 5};
|
||||||
|
int suite_2[5] = {2, 3, 4, 5, 6};
|
||||||
|
for (i = 0; i != 5; i++) {
|
||||||
|
printf("Jet n°%d : ", i+1);
|
||||||
|
scanf("%d", &resultats[i]);
|
||||||
|
getchar();
|
||||||
|
}
|
||||||
|
min = resultats[0];
|
||||||
|
for (j = 0; j != 5; j++) {
|
||||||
|
for (i = 0; i != 5; i++) {
|
||||||
|
if (min >= resultats[i] && resultats[i] != 0) {
|
||||||
|
min = resultats[i];
|
||||||
|
temp = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tab_trie[j] = min;
|
||||||
|
resultats[temp] = 7; /* On prend une valeur en dehors des valeurs autorisées */
|
||||||
|
min = resultats[0]; /* Ce qui fait qu'on aura toujours un minimum qui n'a pas déjà été traité */
|
||||||
|
}
|
||||||
|
for (i = 0; i != 5; i++) {
|
||||||
|
if (tab_trie[i] != suite_1[i] && tab_trie[i] != suite_2[i]) {
|
||||||
|
printf("Ce n'est pas une suite");
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("C'est une suite");
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
@@ -0,0 +1,9 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
printf("%d\n", 31);
|
||||||
|
printf("%o\n", 031);
|
||||||
|
printf("%x\n", 0x31);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
54
DEV1.1/Entrainements/test.c
Normal file
54
DEV1.1/Entrainements/test.c
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
# include <stdio.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
# include <string.h>
|
||||||
|
|
||||||
|
int compte_negatifs(int* t, int taille_t) {
|
||||||
|
if (taille_t == 1) {
|
||||||
|
return (t[taille_t-1] < 0);
|
||||||
|
}
|
||||||
|
return (t[taille_t-1] < 0) + compte_negatifs(t, taille_t-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void afficher_chaine(char* chaine, size_t taille_chaine) {
|
||||||
|
if (taille_chaine == 0) {
|
||||||
|
putchar(chaine[strlen(chaine)]);
|
||||||
|
putchar('\n');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
putchar(chaine[(strlen(chaine) - taille_chaine)]);
|
||||||
|
afficher_chaine(chaine, taille_chaine-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void afficher_chaine_reverse(char* chaine, size_t taille_chaine) {
|
||||||
|
if (taille_chaine == 1) {
|
||||||
|
putchar(chaine[0]);
|
||||||
|
putchar('\n');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
putchar(chaine[taille_chaine-1]);
|
||||||
|
afficher_chaine_reverse(chaine, taille_chaine-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int conversion_base_2(int entier) {
|
||||||
|
if (entier == 1) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (entier == 2) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return (int)strcat((entier % 2 + '0'), ((char) conversion_base_2(entier/2)));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
/* int t[10] = {3, 2, 12,8, -29, 7, 34, 9, 10};
|
||||||
|
printf("%d\n",compte_negatifs(t, 10)); */
|
||||||
|
char* texte = "Go ecrire un roman juste pour voir si une fonction elle marche";
|
||||||
|
afficher_chaine(texte, strlen(texte));
|
||||||
|
afficher_chaine_reverse(texte, strlen(texte));
|
||||||
|
printf("%d\n", conversion_base_2(12));
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
BIN
DEV1.1/SAé/-ansi
Executable file
BIN
DEV1.1/SAé/-ansi
Executable file
Binary file not shown.
BIN
DEV1.1/SAé/3_3/croix_j1.png
Normal file
BIN
DEV1.1/SAé/3_3/croix_j1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.5 KiB |
BIN
DEV1.1/SAé/3_3/croix_j2.png
Normal file
BIN
DEV1.1/SAé/3_3/croix_j2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.6 KiB |
BIN
DEV1.1/SAé/3_3/j1.png
Normal file
BIN
DEV1.1/SAé/3_3/j1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
BIN
DEV1.1/SAé/3_3/j2.png
Normal file
BIN
DEV1.1/SAé/3_3/j2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.0 KiB |
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user