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
|
# include <stdlib.h>
# include <stdio.h>
# include <tgmath.h>
void init(int n_part,float x[n_part],int n_step);
void init(int n_part,float x[n_part], int n_step){
int i,h;
for(h=0;h<n_step;h++){ // je initialise le tableau
for(i=1;i<=n_part;i++){
x[i]=0;
}
}
}
void move(int n_part,float x[n_part],int n_step);
void move(int n_part,float x[n_part],int n_step){
int k,g;
float dxi;
for(g=0;g<n_step;g++){ //je affecte au tableau des valeurs aléatoires
for(k=1;k<=n_part;k++){
dxi=2*(rand()/(RAND_MAX+1.))-1;
x[k]=dxi;
}
}
}
void affiche(int n_part, float x[n_part],int n_step);
void affiche(int n_part,float x[n_part],int n_step ){
int j,c;
for(c=0;c<n_step;c++){ // je affiche les valeurs calculé avec la fonction void
for(j=1;j<=n_part;j++){
printf("x[%d]=%g\n",j,x[j]);
}
}
}
int main(void){
int n_part,n_step; //je declare les variables
printf("saisir un nombre entier\n");
scanf("%d%d",&n_part,&n_step);
printf("la vlaeur saisie n_part = %d et n_step = %d\n",n_part,n_step);
float x[n_part];
init(n_part,x,n_step); // j'applle les differentes fonctions
move(n_part,x,n_step);
affiche(n_part,x,n_step);
exit(EXIT_SUCCESS);
} |
Partager