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]
4 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]4 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
Easy upgrade from windows xp to windows 7
LenaWriter [7]
Firstly you have to go to opera mini then search for upgrading Windows XP to Windows 7 then it will automatically upgrade to Windows 7
6 0
3 years ago
HELPPPPPPP!!!!!!!!!
Andrei [34K]
The compression ratio is 20:1 please mark me brainliest
3 0
3 years ago
What are the atoms in grp one? periodic table. I am going to mark as brainliest ​
Maru [420]

Answer:

Atoms in group 1:

H

Li

Na

K

Rb

Cs

Fr

3 0
4 years ago
Find the ratio of 24 to 36​
miv72 [106K]

Answer:

24:36 if you want it in the smallest form it is 2:3

4 0
3 years ago
Read 2 more answers
Anwser the question below plz due in 15 mins.
klemol [59]
Novels about Harry Potter, a boy who learns on his eleventh birthday that he is the orphaned son of two powerful wizards and possesses unique magical powers of his own. He is summoned from his life as an unwanted child to become a student … More
Releas
6 0
3 years ago
Other questions:
  • What are the best apps to learn coding
    15·2 answers
  • Cpu, ram, rom, and other electronic components are mounted on a board, which is called the
    15·1 answer
  • To run a PHP application that has been deployed on your own computer you can enter a URL in the address bar of your browser that
    7·1 answer
  • Two groups of simple machines and list the simple machines that belong in each group
    7·1 answer
  • The Internet of Things (IoT) is a global information architecture that could contain
    12·1 answer
  • If Digital Assistants are free to use why companies do spend millions of dollars to develop and support them?
    8·1 answer
  • A friend complains that she is always running out of money even though she “never buys anything expensive.” What advice would yo
    5·2 answers
  • Does anyone have a pdf of the greatest by eddie van der meer????
    15·1 answer
  • Copyright ownership analysis starts with this principle: The ________ is the owner.
    6·1 answer
  • Why is a salt added to a password that is being stored in a database?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!