-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabove_average.cpp
56 lines (32 loc) · 1 KB
/
above_average.cpp
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
52
53
54
55
56
#include <cstdio>
#include <cassert>
int main(){
int c, res = scanf("%d", &c);
assert(c > 0 && c <= 50);
for(int j = 0; j < c; j++){
float students , res = scanf("%f", &students);
assert(students > 0 && students <= 1000);
float *scores = new float[(int)students];
for(int i = 0; i < students; i++){
scores[i], res = scanf("%f",&scores[i]);
assert(scores[i] >= 0 && scores[i] <= 100);
}
float sum = 0;
for(int i = 0; i < students; i++){
sum += scores[i];
}
float average = sum / students;
int higher = 0;
for(int i = 0; i < students; i++){
if(scores[i] > average){
higher++;
}
}
float test = higher / students;
float pHigher = (higher / students) * 100;
printf("%.3f",pHigher);
printf("%% \n");
delete [] scores;
}
return 0;
}