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
zepelin [54]
3 years ago
10

Write the definition of a function reverse , whose first parameter is an array of integers and whose second parameter is the num

ber of elements in the array. The function reverses the elements of the array. The function does not return a value.So far I have this and it's telling me that I am not reversing all the elements. I think it might be an offset issue.My code so far:void reverse (int a[], int x){int swap;for (int i=0; i<=x; i++){swap = a[i];a[i] = a[x];a[x] = swap;}return;}
Computers and Technology
1 answer:
Charra [1.4K]3 years ago
3 0

Answer:

To reverse the elements in an array, the codes can be written as follows:

void reverse(int a[], int x)

{

       int swap;

       for(int i = 0; i < x/2 ; i++)

       {

           swap = a[i];

           a[i] = a[x - i - 1];

           a[x - i - 1] = swap;

       }

}

Explanation:

There are two aspects that are worth for our concern:

First, in the for-loop, the condition should be set as "x / 2".  In every iteration, there are two numbers in the array being swapped.

  • a[0] swapped with a[x-1]
  • a[1] swapped with a[x - 2]
  • a[2] swapped with a[x - 3]
  • .....

All the elements in the array shall complete swapping when it reaches its middle index.

Second, to ensure we always take the element from the last and followed with the second last, third last etc in next round of iteration, we need to formulate the index as "x - i - 1"

You might be interested in
The word count of the active document is typically displayed on the ________.
romanna [79]

Click the Word Count in the Proofing Group. Maybe the name is the Bottom ribbon tab

4 0
4 years ago
Suppose that outfile is an ofstream variable and output is to be stored in the file outputData.out. Which of the following state
katrin [286]

Answer:

outFile.open("outputData.out");

4 0
3 years ago
What four things does steering control involve?
Dafna1 [17]

Answer:

putting your hands one the wheel, putting the car in gear, putting your foot on the brakes when you need to, and watch for cars when you're driving. hope it helps

Explanation:

7 0
3 years ago
Focusing on a target market makes it harder to develop products and services that specific groups of customers want.
Sloan [31]

Answer:

ikr so true

Explanation:

5 0
3 years ago
A _____ model is one that is automatically adjusted based on changing relationships among variables.
BabaBlast [244]

Answer: dynamically modified model

Explanation:

7 0
2 years ago
Other questions:
  • A technology _____ begins with the birth of a new technology and ends when that technology reaches its limits and dies as it is
    13·1 answer
  • While driving you encounter an emergency vehicle stopped ahead. Discuss how the move over law applies to this situation and your
    13·1 answer
  • Type the correct answer in the box. Spell the word correctly. What aspect should you consider before adding pictures to a docume
    7·2 answers
  • A ___ is the basic collective unit of data in a computer.
    12·1 answer
  • Consider a network of 8 routers connected together to provide more than one path of connectivity between host A and host B at tw
    8·1 answer
  • Suppose 8 people want to communicate with each other using public key encryption. The communication between any pair of them is
    7·1 answer
  • What is the difference between an internal and an external method call? In what situation would only internal calls be needed?
    11·1 answer
  • Technician A says that S-cams can be left or right handed. Technician B says that S-cam foundation brakes can have one or two an
    15·1 answer
  • Which of the following is a subsystem of computers providing access to the Internet and offering multimedia and linking capabili
    13·1 answer
  • What is the relationship between interoperability and the other quality attributes highlighted in this book? For example, if two
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!