Created
October 18, 2013 08:01
-
-
Save rigibun/7038047 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
#include <cmath> | |
using namespace std; | |
int main(void) | |
{ | |
vector<int> vc; | |
int n; | |
cout << "# of data" << endl; | |
cin >> n; | |
int x; | |
double avg = 0; | |
for(int i = 0; i < n; i++) | |
{ | |
cin >> x; | |
avg += x; | |
vc.push_back(x); | |
} | |
avg /= n; | |
sort(vc.begin(), vc.end()); | |
for(int i = 0; i < n; i++) | |
{ | |
cout << vc[i] << '\t'; | |
if(i % 5 == 4) | |
cout << endl; | |
} | |
int mode = 0; | |
{ | |
int maxmode = 0; | |
int curmode = 0; | |
for(int i = 1; i < n; i++) | |
{ | |
if(vc[i] == vc[i - 1]) | |
curmode++; | |
else | |
curmode = 0; | |
if(curmode > maxmode) | |
{ | |
mode = vc[i]; | |
maxmode = curmode; | |
} | |
} | |
} | |
double median = (n % 2 == 0)? ((vc[n/2] + vc[n/2 + 1])/2) : vc[n/2 + 1]; | |
cout << "avg = " << avg << endl; | |
cout << "mode = " << mode << endl; | |
cout << "median = " << median << endl; | |
double SD = 0; | |
for(int i = 0; i < n; i++) | |
{ | |
SD += (vc[i] - avg) * (vc[i] - avg); | |
} | |
SD /= (n - 1); | |
SD = sqrt(SD); | |
cout << "SD = " << SD << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment