update
This commit is contained in:
26
DEV.1.1/CM2TEST/CM2A/1.Section.c
Normal file
26
DEV.1.1/CM2TEST/CM2A/1.Section.c
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
long int dividende, diviseur;
|
||||
ldiv_t result;
|
||||
|
||||
if (argc < 3) {
|
||||
printf("Usage: %s <dividend> <divisor>\n", argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
sscanf(argv[1], "%ld", ÷nde);
|
||||
sscanf(argv[2], "%ld", &diviseur);
|
||||
|
||||
if (diviseur == 0) {
|
||||
printf("Erreur : le diviseur ne peut pas être zéro.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
result = ldiv(dividende, diviseur);
|
||||
printf("quotient : %ld\n", result.quot);
|
||||
printf("reste : %ld\n", result.rem);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
8
DEV.1.1/CM2TEST/CM2A/2.Separation/Makefile
Normal file
8
DEV.1.1/CM2TEST/CM2A/2.Separation/Makefile
Normal file
@@ -0,0 +1,8 @@
|
||||
carre : carre.o lightness.o
|
||||
gcc -ansi -pedantic -o carre carre.o lightness.o
|
||||
|
||||
lightness.o : lightness.c lightness.h
|
||||
gcc -ansi -pedantic -c lightness.c
|
||||
|
||||
carre.o : carre.c lightness.h
|
||||
gcc -ansi -pedantic -c carre.c
|
BIN
DEV.1.1/CM2TEST/CM2A/2.Separation/carre
Executable file
BIN
DEV.1.1/CM2TEST/CM2A/2.Separation/carre
Executable file
Binary file not shown.
49
DEV.1.1/CM2TEST/CM2A/2.Separation/carre.c
Normal file
49
DEV.1.1/CM2TEST/CM2A/2.Separation/carre.c
Normal file
@@ -0,0 +1,49 @@
|
||||
#include<stdlib.h>
|
||||
#include<stdio.h>
|
||||
#include<time.h>
|
||||
|
||||
#include "lightness.h"
|
||||
|
||||
#define RED 1
|
||||
#define GREEN 2
|
||||
#define BLUE 4
|
||||
#define DARK_RED 124
|
||||
#define DARK_GREEN 34
|
||||
#define DARK_BLUE 19
|
||||
#define LIGHT_RED 217
|
||||
#define LIGHT_GREEN 157
|
||||
#define LIGHT_BLUE 147
|
||||
|
||||
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;
|
||||
}
|
10
DEV.1.1/CM2TEST/CM2A/2.Separation/lightness.c
Normal file
10
DEV.1.1/CM2TEST/CM2A/2.Separation/lightness.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include "lightness.h"
|
||||
|
||||
int lightness(void) {
|
||||
if (time(NULL)%2) {
|
||||
return LIGHT;
|
||||
} else {
|
||||
return DARK;
|
||||
}
|
||||
}
|
10
DEV.1.1/CM2TEST/CM2A/2.Separation/lightness.h
Normal file
10
DEV.1.1/CM2TEST/CM2A/2.Separation/lightness.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef LIGHTNESS_H
|
||||
#define LIGHTNESS_H
|
||||
|
||||
#define LIGHT 0
|
||||
#define DARK 1
|
||||
|
||||
int lightness(void);
|
||||
|
||||
|
||||
#endif /*LIGHTNESS_H*/
|
30
DEV.1.1/CM2TEST/CM2A/4.Sensation-Fichiers.c
Normal file
30
DEV.1.1/CM2TEST/CM2A/4.Sensation-Fichiers.c
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
FILE *flux = fopen("reitne", "rb"); /* Open the file in binary mode */
|
||||
unsigned char bytes[4];
|
||||
unsigned int num;
|
||||
|
||||
if (flux == NULL) {
|
||||
perror("Error opening file");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (fread(bytes, 1, 4, flux) != 4) {
|
||||
perror("Error reading file");
|
||||
fclose(flux);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Combine the bytes into an integer (big-endian to little-endian)*/
|
||||
num = (unsigned int)bytes[0] * 256 * 256 * 256 +
|
||||
(unsigned int)bytes[1] * 256 * 256 +
|
||||
(unsigned int)bytes[2] * 256 +
|
||||
(unsigned int)bytes[3];
|
||||
|
||||
printf("%u\n", num);
|
||||
|
||||
fclose(flux);
|
||||
return 0;
|
||||
}
|
8
DEV.1.1/CM2TEST/CM2A/Makefile
Normal file
8
DEV.1.1/CM2TEST/CM2A/Makefile
Normal file
@@ -0,0 +1,8 @@
|
||||
carre : carre.o lightness.o
|
||||
gcc -ansi -pedantic -o carre carre.o lightness.o
|
||||
|
||||
lightness.o : lightness.c lightness.h
|
||||
gcc -ansi -pedantic -c lightness.c
|
||||
|
||||
carre.o : carre.c lightness.h
|
||||
gcc -ansi -pedantic -c carre.c
|
BIN
DEV.1.1/CM2TEST/CM2A/reitne
Normal file
BIN
DEV.1.1/CM2TEST/CM2A/reitne
Normal file
Binary file not shown.
Reference in New Issue
Block a user