#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define DMAX 10000
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

typedef double Array1D[DMAX];

void InitRandGen(void);
int Array1DRand(Array1D x,int *pN);
double Array1DMean(Array1D x,int dim);
void Array1DPrint(Array1D x,int dim);


int main(){ 
  int N;
  double E;
  Array1D y;
  
  if (!Array1DRand(y,&N))
    return 0;
  Array1DPrint(y,N);
  E=Array1DMean(y,N);
  
  printf("La moyenne est de : %lf\n",E);
  return 1;
}

void InitRandGen(void){
  time_t t1;
  time(&t1);
  srand48((long) t1); /* Intialisation du generateur de V.A. */
}

int Array1DRand(Array1D x,int *pN){
  int i; 
  printf("N=");scanf("%d",pN);
  if ((*pN>DMAX)||(*pN<=0)){
    printf("!!! 0<N<=%d\n",DMAX);
    return 0;
  }
  InitRandGen();
 
  /* Initialisation du tableau x */
  for (i=0;i<*pN;i++)
    x[i]=drand48();
}

double Array1DMean(Array1D x,int dim){
  /* Calcul de la moyenne des elements de x */
  int i;
  double S=0.;
  for (i=0;i<dim;i++)
    S+=x[i];
  return S/dim;
}

void Array1DPrint(Array1D x,int dim){
  /* Calcul de la moyenne des elements de x */
  int i;
  for (i=0;i<dim;i++){
    if (i%10==0)
      printf("\n%d to %d :\n  ",i,MIN(i+9,dim-1));
    printf("%.3f ",x[i]);
  }
  printf("\n");
}
