close
題目概要:
找出分數在平均以上佔多少百分比。
解題方向:
先計算出平均分數後,計算有多少分數是在平均以上,再去計算百分比。
程式碼:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Java | |
import java.util.Scanner; | |
class uva10370{ | |
public static void main(String args[]){ | |
Scanner sc=new Scanner(System.in); | |
int cases=sc.nextInt(); | |
for(int i=0;i<cases;i++){ | |
int n=sc.nextInt(); | |
int grade[]=new int[n]; | |
for(int j=0;j<n;j++){ | |
grade[j]=sc.nextInt(); | |
} | |
//計算平均分數 | |
int total=0; | |
for(int j=0;j<n;j++) total=total+grade[j]; | |
int average=total/n; | |
//計算百分比,並輸出 | |
float count=0; | |
for(int j=0;j<n;j++) if(grade[j]>average) count++; | |
System.out.printf("%.3f%%",count/n*100); | |
System.out.println(""); | |
} | |
} | |
} |
文章標籤
全站熱搜