從鍵盤輸入若干個同學的成績,統計並輸出最高成績 最低成績 平均分,當輸入負數時結束輸入


算法:

 1 #include<iostream>
 2 using namespace std;
 3 int main()
 4 {
 5     float ave,score,max,min,sum=0;
 6     int n=0;   cin>>score;
 7     max=min=score;
 8     while(score>=0)
 9     {
10         sum=sum+score;
11         n++;
12         cin>>score;
13         ave=sum/n;
14         if(score<0) break;
15         if(max<score)
16             max=score;
17         if(min>score)
18             min=score;
19     }
20     cout<<"ave="<<ave<<endl;
21     cout<<"max="<<max<<endl;
22     cout<<"min="<<min<<endl;
23     return 0;
24 }

 運行結果:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM