Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <algorithm>
- using namespace std;
- int a[123];
- int cnt[1001];
- int main() {
- int n;
- scanf("%d", &n);
- double avg = 0;
- for (int i = 0; i < n; ++i){
- scanf("%d", &a[i]);
- avg += a[i];
- ++cnt[a[i]];
- }
- avg /= n;
- sort(a, a+n);
- int n2d = (n-1)/2;
- int n2u = n/2;
- double med = (a[n2d] + a[n2u]) / 2.0;
- int mode = 0;
- for (int i = 0; i <= 1000; ++i) {
- if (cnt[i] >= cnt[mode])
- mode = i;
- }
- printf("%.1lf\n", avg);
- printf("%.1lf\n", med);
- printf("%.1lf\n", (double)mode);
- return 0;
- }
Add Comment
Please, Sign In to add comment