Ajout TPS + Entrainements
This commit is contained in:
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
|
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;
|
||||
}
|
11
DEV1.1/Entrainements/controle_machine_2_B/Makefile
Normal file
11
DEV1.1/Entrainements/controle_machine_2_B/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
carre: carre.o hue.o
|
||||
gcc -ansi -pedantic -o carre carre.o hue.o
|
||||
|
||||
carre.o : carre.c
|
||||
gcc -ansi -pedantic -c carre.c
|
||||
|
||||
hue.o : hue.c hue.h
|
||||
gcc -ansi -pedantic -c hue.c
|
||||
|
||||
run : carre
|
||||
./carre
|
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;
|
||||
}
|
||||
|
12
DEV1.1/Entrainements/controle_machine_2_B/hue.c
Normal file
12
DEV1.1/Entrainements/controle_machine_2_B/hue.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "carre.c"
|
||||
|
||||
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
|
Reference in New Issue
Block a user