From c7ec385a551c1e83b4c687a5b598424355c433a9 Mon Sep 17 00:00:00 2001 From: HORVILLE Ewen Date: Tue, 25 Jan 2022 14:25:17 +0100 Subject: [PATCH] Controle Machine 2 --- APL1.1/CM2/conversion.c | 18 ++++++++++++++++++ APL1.1/CM2/inverse.c | 23 +++++++++++++++++++++++ APL1.1/CM2/lancer.c | 17 +++++++++++++++++ APL1.1/CM2/semaine.c | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+) create mode 100644 APL1.1/CM2/conversion.c create mode 100644 APL1.1/CM2/inverse.c create mode 100644 APL1.1/CM2/lancer.c create mode 100644 APL1.1/CM2/semaine.c diff --git a/APL1.1/CM2/conversion.c b/APL1.1/CM2/conversion.c new file mode 100644 index 0000000..57abbe9 --- /dev/null +++ b/APL1.1/CM2/conversion.c @@ -0,0 +1,18 @@ +#include +#include +#include + +#define FACTOR 2.54 + +int main(int argc, char* argv[]) { + double length = strtod(argv[1], NULL), new_length; + if (!strcmp(argv[2], "cm")) { /*On veut convertir en pouces*/ + new_length = length / FACTOR; + printf("%1.3fcm = %1.3fin\n", length, new_length); + } else { /*On veut convertir en centimètres*/ + new_length = length * FACTOR; + printf("%1.3fin = %1.3fcm\n", length, new_length); + } + + 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..5dd5a5d --- /dev/null +++ b/APL1.1/CM2/inverse.c @@ -0,0 +1,23 @@ +#include +#include + +#define NBINT 5 + +void reverse(int state) { + int entier; + printf("Entier n° %d : ", NBINT - state + 1); + scanf("%d", &entier); + + if (state != 1) /*On demande les autres entiers avant de print !*/ + reverse(state-1); + + printf("%d ", entier); + + if (state == NBINT) + putchar('\n'); /*On retourne à la ligne à la fin.*/ +} + +int main(void) { + reverse(NBINT); + 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..faac862 --- /dev/null +++ b/APL1.1/CM2/lancer.c @@ -0,0 +1,17 @@ +#include +#include + +int main(void) { + FILE* file = fopen("/dev/random", "r"); + if (file) { + unsigned char randVal; + fread(&randVal, 1, 1, file); + + printf("%d\n", (randVal % 6) + 1); + } else { + puts("Impossible d'ouvrir le fichier."); + return EXIT_FAILURE; + } + + 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..f03cc75 --- /dev/null +++ b/APL1.1/CM2/semaine.c @@ -0,0 +1,32 @@ +#include +#include +#include + +char weekDays[7][9] = { + "dimanche", + "lundi", + "mardi", + "mercredi", + "jeudi", + "vendredi", + "samedi" +}; + +int main(void) { + int day, month, year; + printf("Donnez une date au format jj/mm/aa : "); + scanf("%d/%d/%d", &day, &month, &year); + + year += 100; /*On assume que les dates données sont des années 2XXX*/ + month -= 1; + + struct tm partialDate = {}; + partialDate.tm_mday = day; + partialDate.tm_mon = month; + partialDate.tm_year = year; + + mktime(&partialDate); + printf("C'est un %s.\n", weekDays[partialDate.tm_wday]); + + return EXIT_SUCCESS; +} \ No newline at end of file