From 5d7833b36682933084d6ee8d943e6c182e3ce398 Mon Sep 17 00:00:00 2001 From: HORVILLE Ewen Date: Tue, 16 Nov 2021 14:32:27 +0100 Subject: [PATCH] =?UTF-8?q?Contr=C3=B4le=20machine=20n=C2=B01?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- APL1.1/CM1/feston.c | 59 ++++++++++++++++++++++++++++++++++++++++++++ APL1.1/CM1/fleur.c | 15 +++++++++++ APL1.1/CM1/flopee.c | 20 +++++++++++++++ APL1.1/CM1/format.c | 10 ++++++++ APL1.1/CM1/foulees.c | 22 +++++++++++++++++ 5 files changed, 126 insertions(+) create mode 100644 APL1.1/CM1/feston.c create mode 100644 APL1.1/CM1/fleur.c create mode 100644 APL1.1/CM1/flopee.c create mode 100644 APL1.1/CM1/format.c create mode 100644 APL1.1/CM1/foulees.c diff --git a/APL1.1/CM1/feston.c b/APL1.1/CM1/feston.c new file mode 100644 index 0000000..f817763 --- /dev/null +++ b/APL1.1/CM1/feston.c @@ -0,0 +1,59 @@ +#include +#include +#include + +#define LIGNES 10 +#define COLONNES 20 + +int main(int argc, char * argv[]) { + int matrice[LIGNES][COLONNES] = {}; + + int i,j; + for (i = 0; i < LIGNES; i++) { + for (j = 0; j < COLONNES; j++) { + matrice[i][j] = 1; + } + } + + int rd1, rd2; + srand(time(NULL)); + for (i = 0; i < 20; i++) { + rd1 = rand(); + srand(rd1); + rd2 = rand(); + srand(rd2); + + matrice[rd1 % LIGNES][rd2 % COLONNES] = 0; + } + + + for (i = 0; i < LIGNES; i++) { + for (j = 0; j < COLONNES; j++) { + printf("%d", matrice[i][j]); + } + printf("\n"); + } + + int lignes_0 = 0, colonnes_0 = 0; + for (i = 0; i < LIGNES; i++) { + for (j = 0; j < COLONNES; j++) { + if (matrice[i][j] == 0) { + lignes_0++; + break; + } + } + } + + for (i = 0; i < COLONNES; i++) { + for (j = 0; j < LIGNES; j++) { + if (matrice[j][i] == 0) { + colonnes_0++; + break; + } + } + } + + printf("\n%d lignes\n%d colonnes\n", lignes_0, colonnes_0); + return EXIT_SUCCESS; +} + diff --git a/APL1.1/CM1/fleur.c b/APL1.1/CM1/fleur.c new file mode 100644 index 0000000..e637bd5 --- /dev/null +++ b/APL1.1/CM1/fleur.c @@ -0,0 +1,15 @@ +#include +#include + +int main(int argc, char * argv[]) { + puts(" _"); + puts(" _( )_"); + puts(" (_(%)_)"); + puts(" /(_)"); + puts("__ |"); + puts("\\_\\|"); + puts(" |"); + puts(" |"); + return EXIT_SUCCESS; +} + diff --git a/APL1.1/CM1/flopee.c b/APL1.1/CM1/flopee.c new file mode 100644 index 0000000..243b9d2 --- /dev/null +++ b/APL1.1/CM1/flopee.c @@ -0,0 +1,20 @@ +#include +#include + +#define BORNE_MIN 0L +#define BORNE_MAX 999999999L + +int main(int argc, char * argv[]) { + int nb_cubes = 0; + + long i; + for (i = BORNE_MIN; i <= BORNE_MAX; i++) { + if ((i*i*i) <= BORNE_MAX) { + nb_cubes++; + } else break; + } + + printf("Il y a %d cubes entre %ld et %ld.\n", nb_cubes, BORNE_MIN, BORNE_MAX); + return EXIT_SUCCESS; +} + diff --git a/APL1.1/CM1/format.c b/APL1.1/CM1/format.c new file mode 100644 index 0000000..98c75fc --- /dev/null +++ b/APL1.1/CM1/format.c @@ -0,0 +1,10 @@ +#include +#include + +int main(void) { + printf("%u\n", 65u); + printf("%s\n", "65"); + printf("%.0f\n", 65.0); + printf("%hhd\n", 65); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/APL1.1/CM1/foulees.c b/APL1.1/CM1/foulees.c new file mode 100644 index 0000000..88bf833 --- /dev/null +++ b/APL1.1/CM1/foulees.c @@ -0,0 +1,22 @@ +#include +#include +#include + +#define LONGUEUR_TOUR 192 + +int main(int argc, char * argv[]) { + int distance; + printf("Entrez une distance en mètres : "); + scanf("%d", &distance); + + int nb_tours = distance / LONGUEUR_TOUR; + int demi_tour = (distance % LONGUEUR_TOUR) / (LONGUEUR_TOUR/2); + + char reponse[15] = "tour"; + if (nb_tours > 1) strcat(reponse, "s"); + if (demi_tour == 1) strcat(reponse, " et demi"); + + printf("%d %s\n", nb_tours, reponse); + return EXIT_SUCCESS; +} +