First of all, this: var array = []
, and the rest of your code, is not c++
syntax at all, it’s pure javascript. You can’t copy code from one language to another expecting that would compile and run properly.
In order to insert all elemnts from N to 0 and then N again to a vector you need to :
- include the vector library :
#include <vector>
- initiate an N value (from a user, using
cin
in by including iostream for example OR manually, i.e. N = 6) - Read through the following code to see how to enter all numbers wanted numbers to a vector here (use push_back). Note: Also, as @NathanOliver mentioned, you can use reverse if you know N in advanced. look here for simple reference.
- And then, push also N in the end manually (
vec.push_back(N)
)
And I’m really saying that for you, try to work this out yourself before someone here gives you the complete code.
2
solved How to get each iteration in a for loop into a list/vector? (C++)