Ajout des TP
This commit is contained in:
13
BUT1/DEV1.1/CM2_2/CM2/Makefile
Normal file
13
BUT1/DEV1.1/CM2_2/CM2/Makefile
Normal file
@@ -0,0 +1,13 @@
|
||||
carre : carre.o lightness.o
|
||||
gcc -ansi -pedantic -o carre carre.o lightness.o
|
||||
|
||||
lightness.o : lightness.c
|
||||
gcc -ansi -pedantic -c lightness.c
|
||||
|
||||
carre.o : carre.c lightness.h
|
||||
gcc -ansi -pedantic -c carre.c
|
||||
|
||||
clean :
|
||||
rm -f carre.o lightness.o
|
||||
|
||||
.PHONY : clean
|
BIN
BUT1/DEV1.1/CM2_2/CM2/carre
Executable file
BIN
BUT1/DEV1.1/CM2_2/CM2/carre
Executable file
Binary file not shown.
52
BUT1/DEV1.1/CM2_2/CM2/carre.c
Normal file
52
BUT1/DEV1.1/CM2_2/CM2/carre.c
Normal file
@@ -0,0 +1,52 @@
|
||||
#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;
|
||||
}
|
13
BUT1/DEV1.1/CM2_2/CM2/exo1.c
Normal file
13
BUT1/DEV1.1/CM2_2/CM2/exo1.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char* argv[]){ /* ou "char**"" */
|
||||
long numerateur = strtol(argv[1],NULL,10);
|
||||
long denominateur = strtol(argv[2],NULL,10);
|
||||
ldiv_t calcul = ldiv(numerateur,denominateur);
|
||||
|
||||
printf("quotient : %d\n",calcul.quot);
|
||||
printf("reste : %d\n",calcul.rem);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
39
BUT1/DEV1.1/CM2_2/CM2/exo3.c
Normal file
39
BUT1/DEV1.1/CM2_2/CM2/exo3.c
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int* suite(int entier){
|
||||
int i = 0, result = entier, nombre_operation;
|
||||
int* tab;
|
||||
|
||||
for (nombre_operation = 0; (result % 2) != 0; i++){
|
||||
result = result / 2;
|
||||
}
|
||||
|
||||
tab = (int*) malloc(nombre_operation * sizeof(int));
|
||||
tab[0] = entier;
|
||||
|
||||
for (i = 1; (entier % 2) != 0; i++){
|
||||
entier = entier / 2;
|
||||
tab[i] = entier;
|
||||
printf("%d", tab[i]);
|
||||
}
|
||||
|
||||
return tab;
|
||||
}
|
||||
|
||||
int main(void){
|
||||
int i;
|
||||
int* tab1 = suite(5);
|
||||
int* tab2 = suite(6);
|
||||
int* tab3 = suite(7);
|
||||
|
||||
for(i=0;i<10;i++){
|
||||
printf("%d\n",tab1[i]);
|
||||
}
|
||||
|
||||
free(tab1);
|
||||
free(tab2);
|
||||
free(tab3);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
27
BUT1/DEV1.1/CM2_2/CM2/exo4.c
Normal file
27
BUT1/DEV1.1/CM2_2/CM2/exo4.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void){
|
||||
FILE* fichier = NULL;
|
||||
int taille_fichier = 0,entier = 0, resultat_fscanf = 0;
|
||||
|
||||
fichier = fopen("reitne","r");
|
||||
if(fichier == NULL){
|
||||
fputs("reitne inaccessible !\n",stderr);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
fseek(fichier,0L,SEEK_END);
|
||||
taille_fichier = ftell(fichier);
|
||||
|
||||
while(1){
|
||||
resultat_fscanf = fscanf(fichier,"%d",&entier);
|
||||
if(resultat_fscanf != 1){
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf("%d",entier);
|
||||
|
||||
fclose(fichier);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
12
BUT1/DEV1.1/CM2_2/CM2/lightness.c
Normal file
12
BUT1/DEV1.1/CM2_2/CM2/lightness.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include<time.h>
|
||||
#include "lightness.h"
|
||||
|
||||
int lightness(void) {
|
||||
if (time(NULL)%2) {
|
||||
return LIGHT;
|
||||
} else {
|
||||
return DARK;
|
||||
}
|
||||
}
|
9
BUT1/DEV1.1/CM2_2/CM2/lightness.h
Normal file
9
BUT1/DEV1.1/CM2_2/CM2/lightness.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef LIGHTNESS_H
|
||||
#define LIGHTNESS_H
|
||||
|
||||
#define LIGHT 0
|
||||
#define DARK 1
|
||||
|
||||
int lightness(void);
|
||||
|
||||
#endif /* LIGHTNESS_H */
|
Reference in New Issue
Block a user