Ajout des TP

This commit is contained in:
stiti
2024-02-01 13:55:03 +01:00
parent 4fe273c309
commit 113583b37a
228 changed files with 7094 additions and 0 deletions

View 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

Binary file not shown.

View 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;
}

View 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;
}

View 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;
}

View 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;
}

View 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;
}
}

View File

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