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
Press the _______ key to move to the next cell in a row.
swat32
I believe it's
C. Tab
7 0
3 years ago
Read 2 more answers
Most keyboards today are in a
BlackZzzverrR [31]
Qwerty format I think.
6 0
3 years ago
Choose the term to complete the sentence.
netineya [11]

Answer:

raster

Explanation:

-> A <u>raster</u> image consists of a grid of colored pixels.

To choose our answer we can look at the definition for each of the options:

[✘] wireframe - "a skeletal three-dimensional model in which only lines and vertices are represented"

[✘] vector - "denoting a type of graphical representation using straight lines to construct the outlines of objects"

[✔] raster - "a rectangular pattern of parallel scanning lines followed by the electron beam on a television screen or computer monitor'

[✘] rendering - "the processing of an outline image using color and shading to make it appear solid and three-dimensional"

<em>(All definitions are quoted from Oxford Languages)</em>

-> Based on these definitions, raster makes the most sense

Have a nice day!

     I hope this is what you are looking for, but if not - comment! I will edit and update my answer accordingly. (ノ^∇^)

- Heather

4 0
2 years ago
What does www stand for?
Temka [501]
Www stands for world wide web
3 0
3 years ago
Read 2 more answers
We have an internal webserver, used only for testing purposes, at IP address 5.6.7.8 on our internal corporate network. The pack
lukranit [14]

Answer:

Check the explanation

Explanation:

A packet filter firewall is used as a check point between internal corporate network to the outside internet. It blocks all the inbound traffic from the outside hosts trying to initiate a direct TCP connection to the internal corporate webserver. The network design with firewall is shown in the attached image below:

The figures in the attached image below shows an internal corporate network is protected with a packet filter firewall to minimize the inbound traffic from the external network or an internet. Therefore, the packet filter is used as a check point between the network.

The packet filter blocks all attempts by the outside hosts in order to initiate a direct TCP connection to the internal webserver of the internal corporate network.

Going by the second part of the attached image below can can therefore conclude that:

• Rule 1 specifies that, deny any packet with the destination address 5.6.7.8 if the STN flag of TCP header is set.

• Rule 2 specifies that, allow the inbound email traffic from the external source.

• Rule 3 specifies, allows the Outbound TCP traffic from the internal corporate network.

• Rule 4 specifies, allows outbound Email traffic from the internal corporate network to the external network.

• Rule 5 specifies, block any traffic from any source to the any destination.

3 0
3 years ago
Other questions:
  • on average, someone with a bachelor’s degree is estimated to earn _______ times more than someone with a high school diploma
    13·1 answer
  • rray testGrades contains NUM_VALS test scores. Write a for loop that sets sumExtra to the total extra credit received. Full cred
    5·1 answer
  • What can search the internet and select elements based on important words
    10·1 answer
  • What type of engineer is interested in designing, developing, and building different machines, devices, and tools? A.aerospace
    8·2 answers
  • Which of the following is true regarding data acquisition? Because data acquisition is often technical, the research team does n
    15·2 answers
  • What blockchain implementation resulted from bitcoin’s rejection of a recommendation to enhance its scripting language support?
    9·1 answer
  • Now that you have explored several different languages (Python, HTML, CSS, and JavaScript), what can you do to keep straight whi
    7·1 answer
  • Which of these statements correctly describe aspects of testing code? Check all of the boxes that apply.
    14·1 answer
  • Look at (c), is it accurate? ​
    9·2 answers
  • 8.6 Code Practice: Question 2
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!