116k views
3 votes
An vector of  int named a that contains exactly five elements has already been declared and initialized. In addition, an  int variable  j has also been declared and initialized to a value somewhere between 0 and 3. 

Write a single statement that assigns a new value to the element of the vector indexed by  j . This new value should be equal to twice the value stored in the next element of the vector (i.e. the element after the element indexed by  j ). Do not modify any other elements of the vector!

User Sufinawaz
by
5.8k points

1 Answer

7 votes

Answer:

The statement for the question is following:-

a[j]=a[j+1]*2;

Step-by-step explanation:

We have to modify the element at the index j.Since the value of j is between 0 to 3 and the vector contains exactly 5 elements.So j will not exceed the size of vector a.

Now what we have to assign the value at index j is the value double at index next to j that is j+1.So the statement will be

a[j]=a[j+1]*2;

User Dejan S
by
6.8k points