Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.47 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. double *res (double array[], int n, double *pmed, double *pmod, double *psred)
  6. {
  7.    
  8.     int i;
  9.     double sred=0, mediana;
  10.     for (i=0;i<=n;i++)
  11.     sred+=array[i];
  12.    
  13.     // среднее
  14.     sred/=n;    
  15.    
  16.    
  17.     for (i = 0; i < n; i++)
  18.     {
  19.         int j, tmp = 0;
  20.         for (j = (i + 1); j < n; j++)
  21.         {
  22.             if (array[i] < array[j])
  23.             {      
  24.                 tmp = array[i];
  25.                 array[i] = array[j];
  26.                 array[j] = tmp;
  27.             }
  28.         }
  29.     }  
  30.         //медиана
  31.     if (n%2!=0)
  32.         mediana = array [n/2];
  33.     else
  34.         mediana = (array [(n/2)-1] + array[n/2])/2;
  35.    
  36.    
  37.     double moda = array[0], cmax = 0, rmax = 0;
  38.     for (int i = 0; i < n; i++) {
  39.         if (cmax > rmax) {
  40.             rmax = cmax;      
  41.             //мода
  42.             moda =  array[i - 1];    
  43.         }
  44.         cmax = 0;
  45.         for (int j = i; j < n; j++)
  46.            if (array[j] == array[i])
  47.               cmax++;
  48.     }
  49.    
  50.    pmed = &mediana;
  51.    pmod = &moda;
  52.    psred = &sred;
  53.    
  54.     //return  0;
  55.    
  56. }
  57.  
  58. int main()
  59. {
  60.     double a[9] = {10, 2, 12, 5, 8, 1, 32, -22, 2};
  61.     double *pmed, *pmod, *psred;
  62.    
  63.     double* (*f) (double array[], int n, double *pmed, double *pmod, double *psred);
  64.     f = res;
  65.    
  66.     double *b = f(a, 9, pmed, pmod, psred);
  67.     printf("%.2lf %.2lf %.2lf", *b, *(b+1), *(b+2) );
  68.  
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement