1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
juin [17]
3 years ago
6

Reversing the elements of an array involves swapping the corresponding elements of the array: the first with the last, the secon

d with the next to the last, and so on, all the way to the middle of the array. Given an array a and two other int variables, k and temp, write a loop that reverses the elements of the array. Do not use any other variables besides a, k, and temp.
Computers and Technology
1 answer:
Ksivusya [100]3 years ago
4 0

Answer:

// Assume that all variables a, n, temp have been declared.

 // Where a is the array, n is the array length, temp is a temporary

 // storage location.

 // Cycle through the array a.

 // By the time the loop gets halfway,

 // The array would have been reversed.

 // The loop needs not get to the end of the array.

 // Hence, the loop ends halfway into the array i.e n/2.

 for (int k = 0; k < n / 2; k++) {

   

  // Swap first and last, second and next-to-the-last and so on

  temp = a[k];

  a[k] = a[n - k - 1];

  a[n - k - 1] = temp;

 }

Explanation:

Carefully go through the comments in the code.

Hope this helps!

You might be interested in
Ou have just set up a network that will use the tcp/ip protocol, and you want client computers to obtain ip configuration automa
Aleks [24]
DHCP (Dynamic Host Configuration Protocol)
5 0
3 years ago
Anyone else having problems with edg?
Kamila [148]
No what’s your problem on edge
4 0
2 years ago
The main trade-off that all investors must consider is
Talja [164]
<span>The main trade-off that all investors must consider is Risk vs Return
In the end, all the techniques that implemented in investing process is aimed for nothing other than profit.
Current market trend dictates that potential return tend to be higher the riskier the investment is and vice versa.
</span>
3 0
3 years ago
Read 2 more answers
Every workplace should have an emergency plan of action.
pochemuha

Answer:

yes i agree with that the answer is in fact true

Explanation:

follow my in sta gram at grac.ehihi

6 0
2 years ago
Read 2 more answers
What is the recommended point size for a slide title?<br> 12–22<br> 24–40<br> 44–66<br> 54–80
jenyasd209 [6]
12-22 hope this helps :)
3 0
3 years ago
Other questions:
  • You just turned on a four port Ethernet switch (it hasn’t learned any addresses yet) and connected a host to each port. You send
    8·1 answer
  • What are some options available when using the Replace feature?
    13·1 answer
  • Somebody who is good at this stuff, please halp meh ;-;
    6·1 answer
  • Which of the following BEST describes an extranet?
    13·1 answer
  • In general, digital to analog modulation equipment is less expensive than the equipment for encoding digital data into a digital
    8·1 answer
  • Which of the following is true about radio waves? They have short wavelengths. They have high energies. They reveal hot gases. T
    10·2 answers
  • What happens if the addressed device does not respond due to a malfunction during a read operation?
    11·1 answer
  • Write a list comprehension that creates a list containing the numbers that result from the values 1 through 10 being multiplied
    15·1 answer
  • Employers are looking for an employee?<br>​
    9·1 answer
  • Which components must all tasks have? Check all that apply.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!