vectors/vector-0c.cc - C++ preview: Similar program with vectors - variation 3. | Lecture 1 - slide 20 : 34 Program 4 |
#include <iostream> #include <vector> int main(){ using namespace std; vector<double> a{1.0, 2.0, 3.0, 4.0, 5.0}; double sum = 0; a[1] = 2.2; for(auto el: a){ cout << el << endl; sum += el; } cout << "Sum = " << sum << endl; // 15.2 return 0; }