From eecd0b6aa6293b1ff321bb7cfbf9612367751d31 Mon Sep 17 00:00:00 2001 From: Vieira Date: Tue, 25 Jan 2022 15:13:52 +0100 Subject: [PATCH] CM2 --- APL1.1/CM2/conversion.c | 19 ++++++++++++ APL1.1/CM2/inverse.c | 67 ++++++++++++++++++++++++++++++++++++++++ APL1.1/CM2/lancer.c | 17 ++++++++++ APL1.1/CM2/semaine.c | 37 ++++++++++++++++++++++ utilitaire/debordement.c | 19 ++++++++++++ 5 files changed, 159 insertions(+) create mode 100644 APL1.1/CM2/inverse.c create mode 100644 APL1.1/CM2/lancer.c create mode 100644 APL1.1/CM2/semaine.c create mode 100644 utilitaire/debordement.c diff --git a/APL1.1/CM2/conversion.c b/APL1.1/CM2/conversion.c index e69de29..cdaba98 100644 --- a/APL1.1/CM2/conversion.c +++ b/APL1.1/CM2/conversion.c @@ -0,0 +1,19 @@ +#include +#include +#include + +int main(int argc, char * argv[]){ +char* temp; +char* type; +double valeur; +type = argv[2]; +valeur = strtod(argv[1],&temp); +double conversion = 2.54; +if (strcmp(type,"cm")==0){ +printf("%.2lf in\n",valeur / conversion); +} +if (strcmp(type,"in")==0){ +printf("%.2lf cm\n",valeur * conversion); +} + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/APL1.1/CM2/inverse.c b/APL1.1/CM2/inverse.c new file mode 100644 index 0000000..5b3490b --- /dev/null +++ b/APL1.1/CM2/inverse.c @@ -0,0 +1,67 @@ +#include +#include + +typedef struct maillon_s { + struct maillon_s* suivant; + int value; + struct maillon_s* premier; + +} maillon; + +int Empty(maillon* premier) { + if (premier == NULL) { + return 1; + } + return EXIT_SUCCESS; +} + +void Push(int value, maillon* premier) { + maillon* p = malloc(sizeof(maillon)); + if (!Empty(premier)) { + p->value = premier->value; + p->suivant = premier->suivant; + premier->suivant = p; + premier->value = value; + } else { + premier->value = value; + } +} + +int Pop(maillon* premier) { + maillon* p; + int value; + if (Empty(premier)) { + exit(EXIT_FAILURE); + } + value = premier->value; + if (premier->suivant==NULL) { + premier = NULL; + } else { + p = premier->suivant; + premier->value = p->value; + premier->suivant = p->suivant; + free(p); + } + return value; +} + +void AfficherListe(maillon* premier) { + maillon* p; + for (p=premier ; p != NULL; p = p->premier) { + printf("%u %u %u %u %u", p->value); + } + printf("\n"); +} + +int main(int argc, char const argv[]) { + int entier; + int i; + maillon* premier = malloc(sizeof(maillon)); + for(i=1;i<=5;i++) { + printf("Entier n°%d : ",i); + scanf("%d", &entier); + Push(entier, premier); + } + AfficherListe(premier); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/APL1.1/CM2/lancer.c b/APL1.1/CM2/lancer.c new file mode 100644 index 0000000..745bb25 --- /dev/null +++ b/APL1.1/CM2/lancer.c @@ -0,0 +1,17 @@ +#include +#include +#include + +int main(int argc, char const argv[]) +{ + FILE *flux; + int temp=0; + flux = fopen("/dev/random", "r"); + if(flux) + { + fread(&temp,sizeof(int),1,flux); + printf("%d\n", temp%6); + fclose(flux); + } + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/APL1.1/CM2/semaine.c b/APL1.1/CM2/semaine.c new file mode 100644 index 0000000..15028c5 --- /dev/null +++ b/APL1.1/CM2/semaine.c @@ -0,0 +1,37 @@ +#include +#include +#include +int main(int argc, char *argv[]){ + struct tm time; + int jour = time.tm_mday; + int mois = time.tm_mon; + int annee = time.tm_year; + int jour_lettre = 0; + printf ("Entrez une date : \n"); + scanf("%d/%d/%d",&jour,&mois,&annee); + time.tm_year = annee; + time.tm_mon = mois; + time.tm_mday = jour; + if (time.tm_mday%6+1 == 0){ + printf("C'est un Dimanche\n"); + } + if (time.tm_mday%6+1 == 1){ + printf("C'est un Lundi\n"); + } + if (time.tm_mday%6+1 == 2){ + printf("C'est un Mardi\n"); + } + if (time.tm_mday%6+1 == 3){ + printf("C'est un Mercredi\n"); + } + if (time.tm_mday%6+1 == 4){ + printf("C'est un Jeudi\n"); + } + if (time.tm_mday%6+1 == 5){ + printf("C'est un Vendredi\n"); + } + if (time.tm_mday%6+1 == 6){ + printf("C'est un Samedi\n"); + } + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/utilitaire/debordement.c b/utilitaire/debordement.c new file mode 100644 index 0000000..058058e --- /dev/null +++ b/utilitaire/debordement.c @@ -0,0 +1,19 @@ +#include +#include + +int main(int argc, char *argv[]) { + unsigned long int l; + int n = 1; + + + l = 1; + while (l*n != 0) { + l *= n; + n++; + } + n -= 1; + + + printf("valeur de n = %d, valeur de %d! = %lu\n", n, n, l); + return EXIT_SUCCESS; +} \ No newline at end of file