fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. int main()
  5. {
  6. cout << "Please enter the length of the array: ";
  7. int i;
  8. cin >> i;
  9. vector<int> v(i);
  10.  
  11. for(size_t j=0; j < v.size(); ++j)
  12. {
  13. v[j] = 2*j;
  14. cout << v[j] << ' ' ;
  15. }
  16. cout << '\n';
  17. }
  18.  
Success #stdin #stdout 0.02s 2860KB
stdin
10
stdout
Please enter the length of the array: 0 2 4 6 8 10 12 14 16 18