Reversing the elements of an array involves swapping the corresponding elements of the array: the first with the last, the second 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.

Answers

Answer 1
Answer:

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!


Related Questions

Given three String variables that have been declared and given values, firstName, middleName, and lastName, write an expression whose value is the values of each these variables joined by a single space. So if firstName, middleName, and lastName, had the values "Big", "Bill", and "Broonzy", the expression's value would be "Big Bill Broonzy". Alternatively, if firstName, middleName, and lastName, had the values "Jerry", "Lee", and "Lewis", the expression's value would be "Jerry Lee Lewis"
What is information technology?
This question is for one of my classes I am in right now, and the question is: If you were told that your infant was failing to thrive, how would you respond? U MAKE USE THE INTERNET TO ANSWER THIS QUESTION! Thank u, Laurencurnutte784
Match each word to its correct meaning. 1. brick-and-mortar 2. dashboard 3. data warehouse A.) a database that contains a large volume of company data B.) a visual data analysis toolC.) a physical store, as opposed to its "online" presence in a Web site
How does adding a competitor change the dynamics of the ecosystem? Be specific based on your competitor.

Given the declarations struct BrandInfo { string company; string model; }; struct DiskType { BrandInfo brand; float capacity; }; DiskType myDisk; what is the type of myDisk.brand?

Answers

Answer:

Type of myDisk.brand is BrandInfo.

Explanation:

Moore's Law postulates that:This task contains the radio buttons and checkboxes for options. The shortcut keys to perform this task are A to H and alt 1 to alt 9. A a paradigm shift will take place in the technical sciences every two years. B the number of transistors per square inch on integrated circuits will double every two years. C the rate at which new ideas spread through cultures depends on distribution channels. D the members of a given population will usually adopt or accept a new product or innovation.

Answers

Answer:

B. the number of transistors per square inch on integrated circuits will double every two years.

Explanation:

The law has been staying true to its postulation as it has been used in so many fields and for every measure of the capabilities of digital electronic devices, including computer processing speed and memory capacity.

It has led to a paradigm shift , technology adoption life cycle and diffusion innovation theory.

Which of the following statements accurately represents how independent musicians use the Internet? A) Independent musicians primarily use the Internet for personal communication. B) Independent musicians use the Internet solely for selling physical copies of their music. C) Independent musicians extensively use the Internet to distribute their music, connect with fans, and promote their work. D) Independent musicians avoid the Internet as it is not relevant to their careers.

Answers

Answer:

C

Explanation:

Coming from me (a musician) i actually do c

With a DUI charge on a driver’s record ______________.

Answers

When you are charged with DUI or Driving under influence, there are many possible consequences for such crime.

One, your insurance company might require you to increase the price or upgrade your subscription to premium. Or, worst case is they will terminate your subscription immediately upon knowing.

A student is taking a computer course in which there will be four​ tests, each worth 100 points. The student has scores of 92​, 88​, and 94 on the first three tests. The student must make a total of at least 360 in order to get an A. What scores on the last test will give the student an​ A?

Answers

Answer:

He must score 86 or more in the fourth test to get and A

Explanation:

The needed score can be found with this equation

(92+88+94+x) = 360

274 + x =360

x = 360 - 274

= 86

x represents the fourth score, the sum of the four scores must be up-to 360 for the student to get an A

Word, by default, places a tab stop at every ____ mark on the ruler. .25" .5" .75" 1"

Answers

Word, by default, places a tab stop at every .5, otherwise half an inch mark on the ruler.
Hope I helped ;)