//1、建立一個for循環用於輸入數據,設置退出條件 //2、算出平均成績 #include<iostream> using namespace std; int main() { int Score,sum=0,k=0; int a[100]; float Average; cout<<"please input some students's score:"<<endl; for(int i=0;i<100;i++) { cin>>Score; if(Score>0)//判斷是否終止輸入 { k++;//用於計數,記錄滿足條件的輸入內容 a[i]=Score; sum+=Score;//用於累加學生成績 }else { break; } } Average=sum/k; cout<<"平均分為:"<<Average<<endl; cout<<"低於平均分的學生成績有:"<<endl; for(int j=0;j<k;j++) { if(a[j]<Average) { cout<<a[j]<<" "; } } return 0; }
