Help us understand the problem. What is going on with this article?

# Vectorの平均値と中央値を求める

More than 3 years have passed since last update.

## 平均値の求め方

mean.cpp
```float mean(vector<float> v) {
int size = v.size();
float sum = 0;
for (int i = 0; i < size; i++){
sum += v[i];
}
return sum / size;
}
```

## 中央値の求め方

median.cpp
```float median(vector<float> v) {
float size = v.size();
vector<float> _v(v.size());
copy(v.begin(), v.end(), back_inserter(_v));
float tmp;
for (int i = 0; i < size - 1; i++){
for (int j = i + 1; j < size; j++) {
if (_v[i] > _v[j]){
tmp = _v[i];
_v[i] = _v[j];
_v[j] = tmp;
}
}
}
if (size % 2 == 1) {
return _v[(size - 1) / 2];
} else {
return (_v[(size / 2) - 1] + _v[size / 2]) / 2;
}
}
```

Why not register and get more from Qiita?
1. We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
2. you can read useful information later efficiently
By "stocking" the articles you like, you can search right away