Question

state a vector of integers named val. Then write a for loop to push the values...

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

Homework Answers

Answer #1

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.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Create an array named data that can store 100 integers. Write a for loop that loops...
Create an array named data that can store 100 integers. Write a for loop that loops 100 times. Inside the loop store the variable you are using to increment the loop into the current element of the array data. So the array data should have a 0 at index 0, a 1 at index 1, a 2 at index 2, ..., a 99 at index 99.
3. Create vector V of integers randomly distributed on [-10 20] .display the vector. a) Use...
3. Create vector V of integers randomly distributed on [-10 20] .display the vector. a) Use for-end loop to examine each element of the vector. If element is positive double its value ; if element is negative triple its value. Display the result. b) without using for loop find number of elements in V that are greater than 1 c) without using for loop find all of elements in V that are greater or equal to -7 and are less...
Write an R function named fifth with a single vector argument x that calculates and returns...
Write an R function named fifth with a single vector argument x that calculates and returns the sample mean of he 5th, 10th, 15th, ... elements of x. You may assume that x has at least 5 elements.
Please use this template. In this exercise you are to use a vector to store integers...
Please use this template. In this exercise you are to use a vector to store integers entered by the user. Once you have filled the vector, ask the user for a value to search for. If found, remove the value from the vector, keeping all other values in the same relative order, and then display the remaining values. #include <iostream> #include <vector> #include <climits> using namespace std; //Fills vector with user input until user enters 0 (does not include 0...
Write a program that generates a vector with 30 random integers between –10 and 20 and...
Write a program that generates a vector with 30 random integers between –10 and 20 and then finds the maximum of all the elements that are divisible by 3. if you can explain how you got to finding the maximum it well help. also please use matlab
Write a code snippet to accept integer values coming from a user into an array named...
Write a code snippet to accept integer values coming from a user into an array named snippet and takes in 25 items using a do while loop
1) Write a program that stores the first 50 integers to a text file named numbers.txt....
1) Write a program that stores the first 50 integers to a text file named numbers.txt. Each number should appear on a line all by itself.
Program is in C++ Write a function named “removeInvalidDate” that accepts the vector of pointers to...
Program is in C++ Write a function named “removeInvalidDate” that accepts the vector of pointers to Reminder objects. It will go through that list and delete the Reminder objects with an invalid date (day is not between 1 and 31 and month is not between 1 and 12) from the list. It will return how many objects that it has deleted from the list. Reminder class and objects are not given. This is all the question provides.
Write a function in (C++) named - accending_order - that takes a reference to a vector...
Write a function in (C++) named - accending_order - that takes a reference to a vector of string (like {"HI 32", "HELLO 78", "NAME 97", "WORLD 07"}), and returns nothing. The function should reorder the vector so that the courses are sorted by number in ascending order. Write this function without - int (main). CODE IN C++ ONLY. EXPECTED OUTPUT: {"WORLD 07", "HI 32", "HELLO 78", "NAME 97"}
C# code required Write two code segments that print the integers 1 through 10. One segment...
C# code required Write two code segments that print the integers 1 through 10. One segment should use a while loop and the other should use a for loop.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT