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
Romashka [77]
3 years ago
7

Your colleague developed a function, which is supposed to reverse an array of integers, e.g., {1, 5, -10, 7, 23} => {23, 7, -

10, 5, 1}. Test cases show that the function does not work correctly. Please look at the following code and identify all the troubles. Please specify which part(s) of the code will not work and explain why not.
void ReverseArray(int arr[], size_t elements_no) {
size_t i = 0; int x = 0; for (i = 0; i <= elements_no; i++)
{ x = arr[i]; arr[i] = arr[elements_no - i]; arr[elements_no - i] = x; }

}
Computers and Technology
1 answer:
Aliun [14]3 years ago
8 0

Answer:

The parts of the code which makes the program not to work properly is:

1. for (i = 0; i <= elements_no; i++)

2. arr[i] = arr[elements_no - i];

3. arr[elements_no - i] = x;

The correction of the above lines are:

1. for (i = 0; i <= elements_no/2; i++)

2. arr[i] = arr[elements_no - i-1];

3. arr[elements_no - i-1] = x;

Explanation:

It should be noted that the code end up not reversing the array. This happens because the programmer iterates through all the array elements.

i.e.

1. for (i = 0; i <= elements_no; i++)

This will result in the original array.

To solve this problem, the iteration has to stop at the middle element and the correction is:

1. for (i = 0; i <= elements_no/2; i++)

Also, to swap the individual elements 1 has to be subtracted from each array index. So, the following lines:

2. arr[i] = arr[elements_no - i];

3. arr[elements_no - i] = x;

is corrected to:

2. arr[i] = arr[elements_no - i-1];

3. arr[elements_no - i-1] = x;

<em>See attachment for complete corrections</em>

Download txt
You might be interested in
A large multinational client has requested a design for a multi-region database. The master database will be in the EU (Frankfur
12345 [234]

Answer:

RDS with cross-region Read Replicas

Explanation:

The Amazon Web Service, popularly known as the AWS is a subsidiary company of the Amazon.com which provides various cloud computing platforms on demand and Application Programming Interface or the API to other companies, governments and individuals.

The Amazon web services provides an effective RDS. RDS stands for Relational Database Service. The Amazon RDS is used to set up as well as operate and scale relational database in cloud. It provides resizable capacity and cost effective database.

In the context, Amazon Wen Services  can deliver RDS with cross regional Read Replicas.

4 0
3 years ago
What should you point out when demonstrating 2023 murano’s xtronic cvt during full throttle acceleration?.
pav-90 [236]

The thing to point out when demonstrating 2023 murano’s xtronic cvt during full throttle acceleration are:

  • The fast response to its steering input.
  • The way or the level at which Murano stays when cornering.

<h3>What is  throttle acceleration?</h3>

Throttle response is known as vehicle responsiveness and it is one that often measures how fast a vehicle's internal combustion engine, can be able to increase its power output in regards to its response to a driver's need for acceleration.

Hence,The thing to point out when demonstrating 2023 murano’s xtronic cvt during full throttle acceleration are:

  • The fast response to its steering input.
  • The way or the level at which Murano stays when cornering.

Learn more about  throttle acceleration from

brainly.com/question/27962285

#SPJ1

3 0
2 years ago
Which of the following would not count toward a weighted GPA?
marta [7]
D AP music theory is the answer
7 0
3 years ago
Read 2 more answers
Which function in excel should be used to display a value based on a comparison
olga_2 [115]
IF is a Comparison Function 
4 0
4 years ago
Create a program that draws a rectangle whenever you click the mouse. The rectangle should have a width of 30 and a height of 50
Alinara [238K]

Answer:

RECT_HEIGHT = 50

RECT_WIDTH = 30

rect = Rectangle(50,30)

       

# random.choice returns a random value from the COLORS

# function will draw a rectangle at x, y

def draw_rect(x, y):

   rectangle = Rect(50, 30)

   rect.set_position(x, y)

   rect.set_color(Color.green)

   add(rect)

# Link to the mouse click event

   add_mouse_click_handler(draw_rect)

Explanation: Hope this works for you.

6 0
3 years ago
Other questions:
  • What color model should Joe use if he will be using an offset printing press?
    7·1 answer
  • Which of the following statements correctly describe a computer program?
    11·2 answers
  • A network of Bennetton retail sales agents select the Bennetton designs that they feel will appeal to Bennetton retail customers
    10·2 answers
  • Which of the following is the term for software that automatically displays or downloads unwanted offers?
    15·1 answer
  • Which of the following color palettes for the BackColor and ForeColor properties contains colors that are guaranteed to be displ
    8·1 answer
  • A _________________ operating system accepts random enquires from remote locations and provides an instantaneous response
    5·1 answer
  • Being nice take the points​
    9·1 answer
  • what social media application that affect our day to day activities, and how did it improve our skill
    9·1 answer
  • How is enviromental factor a disadvantage of communication​
    9·1 answer
  • Memory containing hardwired instructions that the computer uses when it boots up, before the system loads. In PCs the instructio
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!