Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <algorithm>
- int data[110];
- int modeChk[1010];
- int sum = 0;
- int main() {
- int n;
- scanf("%d", &n);
- int maxMode = -1;
- for (int i = 1; i <= n; ++i) {
- int input;
- scanf("%d", &input);
- sum += input;
- data[i] = input;
- ++modeChk[input];
- if (modeChk[input] > maxMode) maxMode = modeChk[input];
- }
- double mean = 0, med = 0;
- mean = (double)sum / n;
- std::sort(data + 1, data + n + 1);
- if ((n + 1) % 2 == 0) med = (double)data[(int)((n + 1) / 2)];
- else {
- double temp;
- double sumT = 0;
- temp = (double)(n + 1) / (double)2;
- sumT += data[(int)(temp - 0.5)];
- sumT += data[(int)(temp + 0.5)];
- sumT /= (double)2;
- med = sumT;
- }
- printf("%.1lf\n%.1lf\n", mean, med);
- int maxDataMode = -1;
- for (int i = 1; i <= 1000; ++i) {
- if (modeChk[i] == maxMode){
- maxDataMode = i;
- }
- }
- printf("%.1lf",(double)maxDataMode);
- }
Add Comment
Please, Sign In to add comment