算法:
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 }
运行结果: