average score

After an exam, the average score of a class is often calculated.

Please write a program that calculates the average grade for each class.

enter

Enter the first integer n in each line, indicating that there are n people in the class whose average score is to be calculated, followed by the scores of n people.

When n == 0, the input ends and no output is required.

output

Please output the average score for each class with two decimal places.

sample input

2 100 0
3 90 80 70
0
Sample output

50.00
80.00

 

#include<stdio.h>
int main()  
{  
    int n,a,k;  
     float sum; // Attention! sum is float   
    float ave;  
     while (scanf( " %d " ,&n) && n) //Setting here to judge n must be greater than 0
    {  
        k = n;  
        sum = 0 ;  
         while (n-- ) //n fractions
        {  
            scanf("%d",&a);  
            sum += a;  
              
        }  
        ave = sum/k;  
        printf("%.2f\n",ave);  
    }  
    return 0;  
 }   

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324979138&siteId=291194637