+ 7
How to get the cumulative frequency from an array?
I started a project for mean deviation calculation, during which i need a value of median to use in formulae. I an able to easily get the median for ungrouped data, without frequencies. But when i come to grouped data i also need a cumulative frequency, which is an element closest to N in the frequency array. I want to get the closest value to N. How to proceed? c.f. should be closest or equal to n. N is the frequency of the median value...
2 odpowiedzi
+ 5
Thanks!
+ 2
You need to calculate the minimum delta.
#include <iostream>
#include <stdlib.h>
int d, mind=INT_MAX, x, closest=0;
int[100] v;
cout << "x:";
cin >> x;
for(int i=0; i<100; i++)
{
d = abs(x - v[i]);
if (d < mind)
{
mind=d;
closest=v[i];
}
}
cout << "Closer value to " << x << " is " << closest << endl;