#include<iostream>
#include<vector>
using namespace std;
void maxMinAve(vector<int>);
int main(){
vector<int> list;
list.push_back(45);
list.push_back(35);
list.push_back(65);
maxMinAve(list);
return 0;
}
void maxMinAve(vector<int> list){
const int cnt = list.size();
int min = list[0];
int max = min;
int sum = min;
for(int i = 1; cnt > i; i ++){
sum += list[i];
if(min > list[i])
min = list[i];
if(max < list[i])
max = list[i];
}
float avg = (sum/(1.0f*cnt));
cout << "min: " << min << endl;
cout << "max: " << max << endl;
cout << "avg: " << avg << endl;
}
Download
Comments
Post a Comment