state a vector of integers named val. Then write a for loop to push the values 1 through 5 into the elements of the vector stated
The code in c++ is given below.
#include<bits/stdc++.h>
using namespace std;
int main()
{
vector<int>val;
for(int i=1;i<=5;i++)
{
val.push_back(i);
}
cout<<"Displaying the content of the vecotr: ";
for(auto i=val.begin();i!=val.end();++i)
cout<<*i<<" ";
}
The screenshot of the running code and output is given below.
If the answer helped please upvote it means a lot. For any
query please comment.
Get Answers For Free
Most questions answered within 1 hours.