Skip to content

Instantly share code, notes, and snippets.

@kenornotes
Created January 7, 2015 13:34
Show Gist options
  • Save kenornotes/2c4f4e86c2bbdd258396 to your computer and use it in GitHub Desktop.
Save kenornotes/2c4f4e86c2bbdd258396 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main() {
// 輸入學生數量 n
int n;
scanf("%d", &n);
// 輸入 n 個學生成績,並計算成績總和
int grade[n], i, sum = 0;
for(i = 0; i < n; i++) {
scanf("%d", &grade[i]);
sum += grade[i];
}
// 計算並輸出學生平均成績
float avg = (float)sum / n;
printf("average: %f\n", avg);
// 統計有多少位學生成績低於平均
int count = 0;
for(i = 0; i < n; i++) {
if(grade[i] < avg) {
count++;
}
}
// 輸出成績低於平均的學生人數
printf("number: %d\n", count);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment