Contrôle machine n°1

This commit is contained in:
HORVILLE 2021-11-16 14:32:27 +01:00
parent de651f92e5
commit 5d7833b366
5 changed files with 126 additions and 0 deletions

59
APL1.1/CM1/feston.c Normal file
View File

@ -0,0 +1,59 @@
#include<stdio.h>
#include<stdlib.h>
#include <time.h>
#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;
}

15
APL1.1/CM1/fleur.c Normal file
View File

@ -0,0 +1,15 @@
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char * argv[]) {
puts(" _");
puts(" _( )_");
puts(" (_(%)_)");
puts(" /(_)");
puts("__ |");
puts("\\_\\|");
puts(" |");
puts(" |");
return EXIT_SUCCESS;
}

20
APL1.1/CM1/flopee.c Normal file
View File

@ -0,0 +1,20 @@
#include<stdio.h>
#include<stdlib.h>
#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;
}

10
APL1.1/CM1/format.c Normal file
View File

@ -0,0 +1,10 @@
#include <stdio.h>
#include <stdlib.h>
int main(void) {
printf("%u\n", 65u);
printf("%s\n", "65");
printf("%.0f\n", 65.0);
printf("%hhd\n", 65);
return EXIT_SUCCESS;
}

22
APL1.1/CM1/foulees.c Normal file
View File

@ -0,0 +1,22 @@
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#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;
}