1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| #include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
/* Taille du tableau */
#define MAX_LAYER 100
/* Définition de la structure */
typedef struct
{
float depth;
float length;
} layer;
/* Fonction utilitaire d'affichage d'un élément du tableau */
void print_layer(layer *l) {
if (l!=NULL) {
printf("[depth=%.2f; length=%.2f]\n", l->depth, l->length);
}
}
void REINFORCEMENTDEPTH(float defH, int n, layer* tableau) /*la fonction doit me retourner un tableau de N structures layer, et prend comme arguments le nombre d'objet N et un parametre H defini avant*/
{
int i = 0;
for (i=0; i<n; i++)
{
if (i == 0)
tableau[i].depth = 0.5;
else /* (i!=0) */
tableau[i].depth = defH * sqrt(100 * (i-1) / n);
}
}
int main(void)
{
int i = 0;
int n = 10; /* n doit être inférieur à MAX_LAYER */
layer layertable[MAX_LAYER];
/* initialisation du tableau */
memset(layertable, '\0', sizeof(layertable));
REINFORCEMENTDEPTH(0.5, n, layertable);
for (i=0; i<n; i++) {
printf("--> element %d: ", i);
print_layer(&layertable[i]);
}
return EXIT_SUCCESS;
} |