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...
1. Write a function named "countPositiveNegative" that accepts an array of integers, its size and return...
1. Write a function named "countPositiveNegative" that accepts an array of integers, its size and return the number of positive and negative in the array through the use of parameters. In addition, it also returns the number of 0s in the array as the return value. For example, array of {10, 20, -30, -40, 50, 0, 60} will return 4 for positives, 2 for negatives and 1 for 0's as the return value. 2. Write a function named "rotateRight" that...
Write Java code that creates an array of primitive integers named odds and stores all odd...
Write Java code that creates an array of primitive integers named odds and stores all odd numbers between -6 and 38 using a for loop. (Your code will populate the array.) Your code should also enable the array’s size to be exactly large enough to store the numbers. (You will not put a number for the size, your code will determine the number.) (5 pt)
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...