Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- double *res (double array[], int n, double *pmed, double *pmod, double *psred)
- {
- int i;
- double sred=0, mediana;
- for (i=0;i<=n;i++)
- sred+=array[i];
- // среднее
- sred/=n;
- for (i = 0; i < n; i++)
- {
- int j, tmp = 0;
- for (j = (i + 1); j < n; j++)
- {
- if (array[i] < array[j])
- {
- tmp = array[i];
- array[i] = array[j];
- array[j] = tmp;
- }
- }
- }
- //медиана
- if (n%2!=0)
- mediana = array [n/2];
- else
- mediana = (array [(n/2)-1] + array[n/2])/2;
- double moda = array[0], cmax = 0, rmax = 0;
- for (int i = 0; i < n; i++) {
- if (cmax > rmax) {
- rmax = cmax;
- //мода
- moda = array[i - 1];
- }
- cmax = 0;
- for (int j = i; j < n; j++)
- if (array[j] == array[i])
- cmax++;
- }
- pmed = &mediana;
- pmod = &moda;
- psred = &sred;
- //return 0;
- }
- int main()
- {
- double a[9] = {10, 2, 12, 5, 8, 1, 32, -22, 2};
- double *pmed, *pmod, *psred;
- double* (*f) (double array[], int n, double *pmed, double *pmod, double *psred);
- f = res;
- double *b = f(a, 9, pmed, pmod, psred);
- printf("%.2lf %.2lf %.2lf", *b, *(b+1), *(b+2) );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement