asked 138k views
5 votes
.1. Given that an array of int named a has been declared with 12 elements and that the integer variable k holds a value between 2 and 8.

Assign 22 to the element just before a[k] .
2.
Given that an vector of int named a has been declared with 12 elements and that the integer variable k holds a value between 0 and 6.
Assign 9 to the element just after a[k] .
3. Given that an vector of int named a has been declared, and that the integer variable n contains the number of elements of the vector a , assign -1 to the last element in a .

1 Answer

1 vote

Answer:

Step-by-step explanation:

To assign 22 to the element just before a[k] in an array named a with 12 elements and an integer variable k holding a value between 2 and 8, you can use the following code:

a[k - 1 - 1] = 22;

This will assign the value 22 to the element located before a[k] in the array.

To assign 9 to the element just after a[k] in a vector named a with 12 elements and an integer variable k holding a value between 0 and 6, you can use the following code:

a[k + 1] = 9;

This will assign the value 9 to the element located after a[k] in the vector.

To assign -1 to the last element in a vector named a with n elements, where the integer variable n contains the number of elements in the vector, you can use the following code:

a[n - 1] = -1;

This will assign the value -1 to the last element of the vector a.

answered
User Dhananjay Kyada
by
8.4k points