How to get the cumulative frequency from an array? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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...

24th Jan 2017, 2:36 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
2 Answers
+ 5
Thanks!
31st Jan 2017, 5:55 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 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;
31st Jan 2017, 4:57 AM
Ariel Cani
Ariel Cani - avatar