C语言源程序:
#include "stdio.h"
#define MAX 100
void main()
{
int arr[MAX];
int i, size = 0;
int temp;
double sum = 0, avg, rate;
int pass = 0;
while(1)
{
printf("score : ");
scanf("%d", &temp);
if(temp == -1)
break;
arr[size++] = temp;
sum += temp;
if(temp >= 60)
pass++;
}
avg = sum / size;
rate = 1.0 * pass / size;
printf("avg = %.1lf, pass = %.1lf%\n", avg, rate*100);
}
测试输出:
score : 87
score : 45
score : 78
score : 43
score : 100
score : -1
avg= 70.6, pass = 60.0%