debut pile

This commit is contained in:
2024-01-08 14:05:33 +01:00
parent c4bc163fe6
commit cffb424f64
29 changed files with 442 additions and 7 deletions

19
DEV1.1/CM2/Makefile Normal file
View File

@@ -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

48
DEV1.1/CM2/carre.c Normal file
View File

@@ -0,0 +1,48 @@
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
#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;
}

15
DEV1.1/CM2/lightness.c Normal file
View File

@@ -0,0 +1,15 @@
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
#include <lightness.h>
#define LIGHT 0
#define DARK 1
int lightness(void) {
if (time(NULL)%2) {
return LIGHT;
} else {
return DARK;
}
}

8
DEV1.1/CM2/lightness.h Normal file
View File

@@ -0,0 +1,8 @@
#ifndef LIGHTNESS_H
#define LIGHTNESS_H
#define LIGHT 1
#define DARK 0
int lightness(void);
#endif /* LIGHTNESS_H */

17
DEV1.1/CM2/section.c Normal file
View File

@@ -0,0 +1,17 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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;
}

22
DEV1.1/CM2/sensation.c Normal file
View File

@@ -0,0 +1,22 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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<NBR_BYTE;i++){
fread(&octet,sizeof(char),1,fichier);
valeur=strtol(&octet,NULL,10);
entier<<i*8;
entier=valeur;
}
printf("%ld\n",valeur);
fclose(fichier);
return EXIT_SUCCESS;
}

37
DEV1.1/CM2/suite.c Normal file
View File

@@ -0,0 +1,37 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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<NBR_ENT;i++){
tab_val=suite(tab[i]);
printf("tableau de %d\n",tab[i]);
indice=0;
while(tab_val[indice]!=0){
printf("%d\n",tab_val[indice]);
indice++;
}
}
return EXIT_SUCCESS;
}

View File

@@ -12,13 +12,13 @@ int main(int argc,char** argv) {
puts("L'argument 1 n'est pas un entier naturel !");
return EXIT_FAILURE;
} else if (*argv[1] != '\0')
puts("Conversion partielle !");
puts("Conversion partielle du premier entier!");
val2=strtol(argv[2],&pos2,10);
if ((val2 == 0) && (*pos2==argv[2])) {
puts("L'argument 2 n'est pas un entier naturel !");
return EXIT_FAILURE;
} else if (*argv[2] != '\0')
puts("Conversion partielle !");
puts("Conversion partielle du deuxième entier!");
printf("le calcul est égale à %lo\n",val1*val2);
return EXIT_SUCCESS;
}

View File

@@ -2,7 +2,7 @@
#include <stdlib.h>
#include <time.h>
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]){

View File

@@ -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;

27
DEV1.1/TP21/hexadecimal.c Normal file
View File

@@ -0,0 +1,27 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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<y;i++){
if( c[i] ='\n'){
printf("\n");
n=n+10;
}else{
printf("%07d ",n);
fread(&c,3,1,f);
printf("%c ", c[i]);
}
}
}
fclose(f);
return EXIT_SUCCESS;
}

BIN
DEV1.1/TP21/image Executable file

Binary file not shown.

BIN
DEV1.1/TP21/image.bin Normal file

Binary file not shown.

40
DEV1.1/TP21/image.c Normal file
View File

@@ -0,0 +1,40 @@
#include <stdio.h>
#include <stdlib.h>
#include <graph.h>
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<largeur;i++){
fseek(file,8*hauteur/2,SEEK_CUR);
for(j=hauteur/2;j<hauteur;j++){
fread(&c,sizeof(unsigned long),1,file);
ChoisirCouleurDessin(c);
DessinerPixel(i, j);
DessinerPixel(i, j-(-1*(hauteur/2)-j));
DessinerPixel(i-(-1*(largeur/2-i)), j);
DessinerPixel(i-(-1*(largeur/2-i)), j-(-1*(hauteur/2-j)));
}
}
Touche();
FermerGraphique();
fclose(file);
return EXIT_SUCCESS;
}

BIN
DEV1.1/TP24/maximum Executable file

Binary file not shown.

67
DEV1.1/TP24/maximum.c Normal file
View File

@@ -0,0 +1,67 @@
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
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;i<nombre-1;i++){
*liste=ajouter_debut(*liste, rand()%((999-111)+111));
}
}
unsigned short grand(maillon* premier){
unsigned short val;
val=premier->valeur;
premier=premier->suivant;
for(;premier!=NULL;premier=premier->suivant){
if (val<premier->valeur)
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;
}

BIN
DEV1.1/TP26/fibonacci Executable file

Binary file not shown.

15
DEV1.1/TP26/fibonacci.c Normal file
View File

@@ -0,0 +1,15 @@
#include <stdio.h>
#include <stdlib.h>
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;
}

BIN
DEV1.1/TP26/fibonacci2 Executable file

Binary file not shown.

15
DEV1.1/TP26/fibonacci2.c Normal file
View File

@@ -0,0 +1,15 @@
#include <stdio.h>
#include <stdlib.h>
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;
}

BIN
DEV1.1/TP26/phase Executable file

Binary file not shown.

18
DEV1.1/TP26/phase.c Normal file
View File

@@ -0,0 +1,18 @@
#include <stdio.h>
#include <stdlib.h>
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*/

BIN
DEV1.1/TP26/tableau Executable file

Binary file not shown.

17
DEV1.1/TP26/tableau.c Normal file
View File

@@ -0,0 +1,17 @@
#include <stdio.h>
#include <stdlib.h>
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;
}

BIN
DEV1.1/TP27/curiosite Executable file

Binary file not shown.

18
DEV1.1/TP27/curiosite.c Normal file
View File

@@ -0,0 +1,18 @@
#include <stdio.h>
#include <stdlib.h>
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*/

26
DEV1.1/TP27/triangle.c Normal file
View File

@@ -0,0 +1,26 @@
#include <stdio.h>
#include <stdlib.h>
#include <graph.h>
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();
}

28
DEV1.1/TP28/chaine.c Normal file
View File

@@ -0,0 +1,28 @@
#include <stdio.h>
#include <stdlib.h>
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;
}

BIN
DEV1.1/felix-vi_CM2.tar.gz Normal file

Binary file not shown.