Question: Make the following changes to your program at the indicated spots (you should not use indexes anywhere in the program, only pointers): 1.Assign the address

Make the following changes to your program at the indicated spots (you should not use indexes anywhere in the program, only pointers):

1.Assign the address of the last element of the array to last.

2.Add code that prints the addresses of the array elements separated by spaces.

3.Add code that prints the values in the array in reverse order.

4.Add code that prints the every second value of the array.

5.Add code that prints every nth value of the array (where n is given by the user).

Here is the program:

/* Lab 9 Program works with arrays using pointers to reference elements instead of indexes. */ #include  #include  using namespace std; int main(int argc, char *argv[]) { // initialize a 1 dimensional array int arr [10] = {2, 4, 5, 6, 7, 8, 9, 10, 11, 13}; // pointer that moves thru an array to visit elements int *mover, *last; // a pointer to the last element of the array int n; // n is a step size for moving thru the array last = cout << "The array in forward direction is: "; // print array in forward direction for (mover = arr; mover <= last; mover++) cout << *mover << " "; cout << " The array addresses in forward are: "; // print the array addresses in forward order cout << " The array in reverse direction is: "; // print array in reverse direction cout << " Every second element of the array is: "; // print every second element of the array cout << " Enter an array step: "; cin >> n; cout << " Every nth element of the array is: "; // print every nth element of the array cout << " "; return 0; } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!