APL/APL1.1/CM1/feston.c
2021-11-16 14:32:27 +01:00

60 lines
968 B
C

#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;
}