vectors/vector-0a.cc - C++ preview: Similar program with vectors - variation 2. | Lecture 1 - slide 20 : 34 Program 3 |
#include <iostream> #include <vector> int main(){ using std::vector; using std::cout; using std::endl; 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; }