Advertisement
Patresss

1.4

Sep 2nd, 2014
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. int compare(const void *a, const void *b)
  2. {
  3.   return *(double*)a-*(double*)b;
  4. }
  5.  
  6. double min_max_avg(double *min, double *max, int n, ...) // te trzy kropki na koncu nie sluza do wypelnienia jakby ktos nie wiedzial :P
  7. {
  8.   double *tab=malloc(n*sizeof(double));
  9.   if(!tab){
  10.     printf ("BLAD!!\n");
  11.     return -1;
  12.   }
  13.  
  14.  va_list argptr;
  15.  va_start (argptr,n);
  16.  
  17.   int i=0;
  18.   double sum=0;
  19.  
  20.   for(;i<n;i++) {
  21.     tab[i] = va_arg (argptr,double);
  22.     sum += tab[i];
  23.   }
  24.  
  25.   qsort(tab,n,sizeof(double),compare);
  26.   *min=tab[0];
  27.   *max=tab[n-1];
  28.  va_end (argptr);
  29.  printf("min=%lf max=%lf srednia=%lf",*min,*max,sum/n);
  30.   return sum/n;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement