-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathILoveStatistics.cpp
More file actions
51 lines (40 loc) · 841 Bytes
/
ILoveStatistics.cpp
File metadata and controls
51 lines (40 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<stdio.h>
void sort(double arr[], double n){
for(int i = 0; i < n - 1; i++){
for(int j = 0; j < n-i-1; j++){
if(arr[j] > arr[j+1]){
double temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}
int main(){
int t;
scanf("%d", &t);
for(int i = 0; i < t; i++){
int n;
scanf("%d", &n);
double arr[n+1];
double total = 0;
for(int j = 0; j < n; j++){
scanf("%lf", &arr[j]);
total += arr[j];
}
sort(arr, n);
double mean = total/n;
double median = 0;
if(n == 1){
median = arr[0];
}else if(n % 2 == 0){
median = (arr[n/2] + arr[(n/2) - 1]) / 2;
} else{
median = arr[n/2];
}
printf("Case #%d:\n", i+1);
printf("Mean : %.2lf\n", mean);
printf("Median : %.2lf\n", median);
}
return 0;
}