diff --git a/DEV1.1/CM2/Makefile b/DEV1.1/CM2/Makefile new file mode 100644 index 0000000..47d4bb5 --- /dev/null +++ b/DEV1.1/CM2/Makefile @@ -0,0 +1,19 @@ +but : separation + +OFILES = carre.o\ + lightness.o + +CC = gcc + +CFLAGS = -Wall -ansi -pedantic + +carre.o : lightness.h +lightness.o : lightness.h + +separation : $(OFILES) + $(CC) $(CFLAGS) -o separation $(OFILES) + +clean : + -rm -f $(OFILES) separation + +.PHONY : but clean diff --git a/DEV1.1/CM2/carre.c b/DEV1.1/CM2/carre.c new file mode 100644 index 0000000..4bcdcb0 --- /dev/null +++ b/DEV1.1/CM2/carre.c @@ -0,0 +1,48 @@ +#include +#include +#include + +#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; +} \ No newline at end of file diff --git a/DEV1.1/CM2/lightness.c b/DEV1.1/CM2/lightness.c new file mode 100644 index 0000000..546cc42 --- /dev/null +++ b/DEV1.1/CM2/lightness.c @@ -0,0 +1,15 @@ +#include +#include +#include +#include + +#define LIGHT 0 +#define DARK 1 + +int lightness(void) { + if (time(NULL)%2) { + return LIGHT; + } else { + return DARK; + } +} \ No newline at end of file diff --git a/DEV1.1/CM2/lightness.h b/DEV1.1/CM2/lightness.h new file mode 100644 index 0000000..4c84414 --- /dev/null +++ b/DEV1.1/CM2/lightness.h @@ -0,0 +1,8 @@ +#ifndef LIGHTNESS_H +#define LIGHTNESS_H +#define LIGHT 1 +#define DARK 0 + +int lightness(void); + +#endif /* LIGHTNESS_H */ diff --git a/DEV1.1/CM2/section.c b/DEV1.1/CM2/section.c new file mode 100644 index 0000000..68a6c1d --- /dev/null +++ b/DEV1.1/CM2/section.c @@ -0,0 +1,17 @@ +#include +#include +#include + + +int main(int argc, char** argv){ + ldiv_t division; + long int num, den; + if (argc!=3) + printf("Il manque des argument!"); + num=strtol(argv[1],NULL,10); + den=strtol(argv[2],NULL,10); + division=ldiv(num,den); + printf("quotient : %ld\n",division.quot); + printf("reste : %ld\n",division.rem); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/DEV1.1/CM2/sensation.c b/DEV1.1/CM2/sensation.c new file mode 100644 index 0000000..5b14cdc --- /dev/null +++ b/DEV1.1/CM2/sensation.c @@ -0,0 +1,22 @@ +#include +#include +#include +#define NBR_BYTE 4 + + +int main(int argc, char** argv){ + int i,j=0; + long valeur,entier; + char octet; + FILE* fichier=NULL; + fichier= fopen("reitne","r"); + for (i=0;i +#include +#include +#define NBR_VAL 10 +#define NBR_ENT 3 +#define NBR_ENT1 20 +#define NBR_ENT2 18 +#define NBR_ENT3 14 + +int* suite(int valeur){ + int compteur=0; + int* tab=NULL; + tab=(int*) calloc(NBR_VAL,sizeof(int)); + while (valeur%2==0){ + tab[compteur]=valeur; + valeur=valeur/2; + compteur++; + } + tab[compteur]=valeur; + return tab; +} + +int main(void){ + int i,indice; + int tab[NBR_ENT]={NBR_ENT1,NBR_ENT2,NBR_ENT3}; + int* tab_val=NULL; + for (i=0;i #include -int remplissage( int tab[10]){ +void remplissage( int tab[10]){ int tour,signe; int tab_temp[2]; srand(time(NULL)); @@ -13,14 +13,12 @@ int remplissage( int tab[10]){ signe=rand()%2; tab[tour]=tab_temp[signe]; } - return *tab; } -int inversion(const int tab[10], int tab_inv[10]){ +void inversion(const int tab[10], int tab_inv[10]){ int tour; for (tour=0;tour<10;tour++) tab_inv[tour]=tab[(9-tour)]; - return *tab_inv; } void affichage( int tab[10]){ diff --git a/DEV1.1/TP16/binomial.c b/DEV1.1/TP16/binomial.c index b120ab2..b734e29 100644 --- a/DEV1.1/TP16/binomial.c +++ b/DEV1.1/TP16/binomial.c @@ -38,7 +38,7 @@ int main(void) { } /* affichage du resultat */ - printf("C(%d, %d) = %d\n", n, k,(i*i)-j); + printf("C(%d, %d) = %d\n", n, k,mem[i+j]); return EXIT_SUCCESS; diff --git a/DEV1.1/TP21/hexadecimal.c b/DEV1.1/TP21/hexadecimal.c new file mode 100644 index 0000000..d86c76d --- /dev/null +++ b/DEV1.1/TP21/hexadecimal.c @@ -0,0 +1,27 @@ +#include +#include +#include + +int main(int argc, char const *argv[]) +{ + FILE* f; + int i; + int n = 0; + int y; + char c[100]; + f=fopen(argv[1],"r"); + while(feof(f)==1){ + for(i=0;i +#include +#include + +int main(int argc, char const *argv[]) +{ + FILE* file; + file = fopen("image.bin","r"); + int i, j; + int largeur, hauteur; + couleur c; + + fread(&largeur,sizeof(int),1,file); + fread(&hauteur,sizeof(int),1,file); + + printf("%d\n",largeur); + printf("%d\n",hauteur); + + InitialiserGraphique(); + CreerFenetre(10, 10, largeur, hauteur); + fseek(file,8*largeur/2*hauteur,SEEK_CUR); + for(i=largeur/2;i +#include +#include + +struct maillon_s { + unsigned short valeur; + struct maillon_s* suivant; +}; +typedef struct maillon_s maillon; + +maillon* ajouter_debut(maillon* premier, unsigned short nouveau) { + maillon* p = (maillon*) malloc(sizeof(maillon*)); + if (p) { + p->suivant = premier; + p->valeur = nouveau; + } + return p; +} + +void creer(maillon** liste, int nombre){ + int i; + srand(time(NULL)); + *liste=ajouter_debut(*liste, rand()%((999-111)+111)); + for (i=0;ivaleur; + premier=premier->suivant; + for(;premier!=NULL;premier=premier->suivant){ + if (valvaleur) + val=premier->valeur; + } + return val; +} + +void afficher(maillon* premier) { + maillon* p; + for(p = premier; p != NULL; p = p->suivant) + printf("%d ", p->valeur); +} + +void vider(maillon* premier){ + maillon* p; + maillon* q; + for(p = premier; p != NULL; p = q){ + q=p->suivant; + free(p); + } + premier=NULL; +} + +int main(void){ + int val=10; + unsigned short plus_grand; + maillon* liste=NULL; + creer(&liste,val); + afficher(liste); + plus_grand=grand(liste); + printf("\n%d \n", plus_grand); + vider(liste); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/DEV1.1/TP26/fibonacci b/DEV1.1/TP26/fibonacci new file mode 100755 index 0000000..4af2f96 Binary files /dev/null and b/DEV1.1/TP26/fibonacci differ diff --git a/DEV1.1/TP26/fibonacci.c b/DEV1.1/TP26/fibonacci.c new file mode 100644 index 0000000..555b6d5 --- /dev/null +++ b/DEV1.1/TP26/fibonacci.c @@ -0,0 +1,15 @@ +#include +#include + +int fibonacci(int n, int val, int valeur){ + int nombre; + if (n==0){ + printf("%d\n",val); + } + fibonacci(n-1, valeur, val+valeur); +} + +int main(){ + fibonacci(9,0,1); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/DEV1.1/TP26/fibonacci2 b/DEV1.1/TP26/fibonacci2 new file mode 100755 index 0000000..8661792 Binary files /dev/null and b/DEV1.1/TP26/fibonacci2 differ diff --git a/DEV1.1/TP26/fibonacci2.c b/DEV1.1/TP26/fibonacci2.c new file mode 100644 index 0000000..03d2604 --- /dev/null +++ b/DEV1.1/TP26/fibonacci2.c @@ -0,0 +1,15 @@ +#include +#include + +int fibonacci(int n, int val, int valeur){ + int nombre; + if (n){ + printf("%d\n",val); + fibonacci(n-1, valeur, val+valeur); + } +} + +int main(){ + fibonacci(15,0,1); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/DEV1.1/TP26/phase b/DEV1.1/TP26/phase new file mode 100755 index 0000000..fe967a4 Binary files /dev/null and b/DEV1.1/TP26/phase differ diff --git a/DEV1.1/TP26/phase.c b/DEV1.1/TP26/phase.c new file mode 100644 index 0000000..be08322 --- /dev/null +++ b/DEV1.1/TP26/phase.c @@ -0,0 +1,18 @@ +#include +#include + +void exemple(unsigned n) { + if (n != 0) { + putchar('>'); + exemple(n-1); + putchar('<'); + } else + putchar('O'); +} + +int main(){ + exemple(5); + return EXIT_SUCCESS; +} +/*phase ascendente prmier puchar puis troisième putchar et phase +descendante au deuxième putchar*/ \ No newline at end of file diff --git a/DEV1.1/TP26/tableau b/DEV1.1/TP26/tableau new file mode 100755 index 0000000..b5dda55 Binary files /dev/null and b/DEV1.1/TP26/tableau differ diff --git a/DEV1.1/TP26/tableau.c b/DEV1.1/TP26/tableau.c new file mode 100644 index 0000000..b55154f --- /dev/null +++ b/DEV1.1/TP26/tableau.c @@ -0,0 +1,17 @@ +#include +#include + +void afficher(double tab[], int taille){ + if (taille>1){ + printf("%f, ",tab[0]); + afficher(tab+1, taille-1); + }else{ + printf("%f\n",tab[0]); + } +} + +int main(){ + double tab[5]={1.25, 47.80, 77.01, 54.23, 895.14}; + afficher(tab, 5); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/DEV1.1/TP27/curiosite b/DEV1.1/TP27/curiosite new file mode 100755 index 0000000..f6f3e37 Binary files /dev/null and b/DEV1.1/TP27/curiosite differ diff --git a/DEV1.1/TP27/curiosite.c b/DEV1.1/TP27/curiosite.c new file mode 100644 index 0000000..0558b94 --- /dev/null +++ b/DEV1.1/TP27/curiosite.c @@ -0,0 +1,18 @@ +#include +#include + +int f(int n) { + if (n>100) + return n-10; + else + return f(f(n+11)); +} + +int main(){ + int i; + for (i=0; i<101; i++) + printf("%d\n",f(88)); +} + +/*Pour les n<101 +f renvoie 91*/ \ No newline at end of file diff --git a/DEV1.1/TP27/triangle.c b/DEV1.1/TP27/triangle.c new file mode 100644 index 0000000..948b06e --- /dev/null +++ b/DEV1.1/TP27/triangle.c @@ -0,0 +1,26 @@ +#include +#include +#include + +void triangle(int x1, int y1, int x2, int y2, int x3, int y3,int n){ + if (n == 0){ + DessinerSegment(x1, y1, x2, y2); + DessinerSegment(x2, y2, x3, y3); + DessinerSegment(x3, y3, x1, y1); + }else{ + triangle(x1, y1, (x2+x1)/2, y2, (x3+x1)/2, (y3+y2)/2, n-1); + triangle((x1+x2)/2, y1, x2, y2, (x3+x2)/2, (y3+y2)/2, n-1); + triangle((x1+x3)/2, (y1+y3)/2, (x2+x3)/2, (y2+y3)/2, x3, y3, n-1); + } + +} + +int main(){ + int n; + printf("entrez un entier : "); + scanf("%d",&n) + InitialiserGraphique(); + CreerFenetre(10, 10, 1000, 800); + triangle(10, 790, 990, 790, 500, 10, n); + FermerGraphique(); +} \ No newline at end of file diff --git a/DEV1.1/TP28/chaine.c b/DEV1.1/TP28/chaine.c new file mode 100644 index 0000000..1460dff --- /dev/null +++ b/DEV1.1/TP28/chaine.c @@ -0,0 +1,28 @@ +#include +#include + +struct maillon_s { + char valeur; + struct maillon_s* suivant; +}; +typedef struct maillon_s maillon ; + +void push(char nouv, maillon* debut){ + maillon* m = (maillon*) malloc (sizeof(maillon)); + m->valeur = nouv; + if (debut == NULL) + m->suivant = NULL; + else + m->suivant = debut; + debut = m; +} + +void pop(maillon* debut){ + maillon* m = (maillon*) malloc (sizeof(maillon)); + m->valeur = nouv; + if (debut == NULL) + m->suivant = NULL; + else + m->suivant = debut; + debut = m; +} \ No newline at end of file diff --git a/DEV1.1/felix-vi_CM2.tar.gz b/DEV1.1/felix-vi_CM2.tar.gz new file mode 100644 index 0000000..d41bd6e Binary files /dev/null and b/DEV1.1/felix-vi_CM2.tar.gz differ