debut pile
This commit is contained in:
19
DEV1.1/CM2/Makefile
Normal file
19
DEV1.1/CM2/Makefile
Normal 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
48
DEV1.1/CM2/carre.c
Normal 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
15
DEV1.1/CM2/lightness.c
Normal 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
8
DEV1.1/CM2/lightness.h
Normal 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
17
DEV1.1/CM2/section.c
Normal 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
22
DEV1.1/CM2/sensation.c
Normal 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
37
DEV1.1/CM2/suite.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user