#include <vector>
vector<int> v = {1, 2, 3};
v.push_back(4); // {1,2,3,4}
v.pop_back(); // {1,2,3}
v.size() // 3
v[1] // 2
v.front() // 1
v.back() // 3
v.empty() // false
v.clear() // empty vector {}
vector<int> a(5, 0); // 5 zeros: {0,0,0,0,0}
vector<int> b(a); // copy of a
for (int x : v) { cout << x; } // by value
for (const int& x : v) { cout << x; } // by const ref (no copy)
for (int& x : v) { x *= 2; } // by ref (can modify)
Write vectorSum(vector<int> v) and vectorAvg(vector<int> v) that return the sum and average (as double) of all elements.
Click "Run" to execute your code.