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.
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.
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...
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
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.
2.) In order to have a loop that allows the user to input 10 values, what...
2.) In order to have a loop that allows the user to input 10 values, what would be entered in the blank below: int counter = _________; while (counter < 10) { inputVal = Console.ReadLine(); ++counter; } 3.)What is produced from the following code segment? for (int i = 1; i < 5; i++) WriteLine(i); Nothing is displayed Outputs 5 thru 9 Outputs 10 Outputs 1 thru 4 Outputs 1 thru 5 Outputs 10 thru 14 Outputs 0 thru 4...
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.
TestQueue.java Design a class named Queue for storing integers. Like a stack, a queue holds elements....
TestQueue.java Design a class named Queue for storing integers. Like a stack, a queue holds elements. But in a queue, the elements are retrieved in a first-in first-out fashion. The class contains: An int[] data field named elements that stores the int values in the queue. A data field named size that stores the number of elements in the queue. A constructor that creates a Queue object with default capacity 8. The method enqueue(int v) that adds v into the...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT