void affiche(int tableau[], int taille){
int i;
for (i=0; i< taille; i++){
printf(tableau[i], "\n");
}
}
void affiche(int tableau[], int taille){
printf("[");
for (int i = 0; i < (taille-1); i++){
printf("%d;", tableau[i]);
}
printf("%d] \n", tableau[taille-1]);
}
// renvoie le crible d'ératosthène, où l'indice 0 correspond à 2,
// et l'indice n-2 correspond à n
bool* eratosthene(int n) {
// l'indice 0 correspond à 2
bool* crible = malloc(sizeof(bool) * (n - 1));
for(int i = 0; i < n - 1; i++) crible[i] = true;
for(int i = 0; i < n - 1; i++){
if(!crible[i]) continue;
int x = i + 2;
bool crible_modifie = false;
for(int k = 2; k * x <= n; k++){
crible_modifie |= crible[k * x - 2];
crible[k * x - 2] = false;
}
}
return crible;
}
void eratosthene(int n) {
bool* tab = malloc((n+1) * sizeof(bool));
for (int i = 0; i <= n;i++) {
tab[i] = false;
}
tab[0] = true;
tab[1] = true;
int cp = 0;
for (int i = 1; i <= n; i++) {
if (!tab[i]) {
cp++;
for (int j = 2*i; j <= n; j+=i) {
tab[j] = true;
}
}
}
printf("%lld\n", cp);
free(tab);
}
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define int long long
signed main() {
int n = 10;
int m = 10;
srand(time(NULL));
char**tab = malloc(n*sizeof(char*));
for (int i = 0; i < n; i++) {
tab[i] = malloc(m*sizeof(char));
for (int j = 0; j < m; j++) {
tab[i][j] = (rand()%2==0?' ':'X');
if (i == 0 || j == 0 || i == n-1 || j == m-1) {
tab[i][j] = 'X';
} else if (i%2 == 0 && j%2 == 0) {
tab[i][j] = 'X';
} else if (i%2 == 1 && j%2 == 1) {
tab[i][j] = ' ';
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
printf("%c", tab[i][j]);
}
printf("\n");
free(tab[i]);
}
free(tab);
return 0;
}
Maze* empty_maze(int n, int m) {
Maze* maze = malloc(sizeof(Maze));
maze->m = m;
maze->n = n;
int** walls = malloc(sizeof(int)*n*m);
for(int i = 0; i < n; i++) {
walls[i] = malloc(sizeof(int)*n);
for(int j = 0; j < n; j++) walls[i][j] = 1;
}
maze->walls = walls;
return maze;
}