URI Online Judge Solution 1214 Above Average Using C, Python Programming Language.
It is said that 90% of frosh expect to be above average in their class. You are to provide a reality check.
Input
The input contains many test cases. The first line of standard input contains an integer C, the number of test cases. C data sets follow. Each data set begins with an integer, N, the number of people in the class (1 ≤ N ≤ 1000). N integers follow, separated by spaces or newlines, each giving the final grade (an integer between 0 and 100) of a student in the class.
Output
For each case you are to output a line giving the percentage of students whose grade is above average, rounded to 3 decimal places.
Sample Input | Sample Output |
5 | 40.000% |
Solution Using C:
#include<stdio.h>
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,i,s=0,c=0;
float x=0.0;
scanf("%d",&n);
int arr[n];
for(i=0; i<n; i++)
{
scanf("%d",&arr[i]);
s += arr[i];
}
x = (float)s/(float)n;
for(i=0; i<n; i++)
{
if(x<(float)arr[i])
c++;
}
printf("%.3f%%\n",((float)c*100)/(float)n);
}
return 0;
}
Comments
Post a Comment