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
If there has been no change in the data regarding a specific person, place or thing, information about that person, place or thi
babymother [125]
I think it’s b false sorry if I was wrong
6 0
3 years ago
Which two security regulations does the PCI enforce with regard to electronic banking?
Sever21 [200]

The two security regulations the PCI enforce in regards to electronic banking are an external Qualified Security Assessor (QSA) or by a firm specific Internal Security Assessor that creates a Report on Compliance for organizations handling large volumes of transactions, or by Self-Assessment Questionnaire (SAQ) for companies handling smaller volumes.

5 0
3 years ago
Read 2 more answers
At what two layers of the osi model are lan and wan protocols likely to differ??
Anuta_ua [19.1K]
A LAN is connecting two or more computers to form a cable network between them.
<span>A WAN is connecting two or more computers over a broad area to form a cable network between them.</span>
5 0
4 years ago
1.
Hatshy [7]

Answer:

Hi!

The following Javascript statement compares if num is 2 or 5 and increment num by 1 if true.

if ( num==2 || num==5)  

num = num +1;

Explanation:

The operator == is used to compare if the operands are equal.

The operator || is OR.

  • If at least one of the operands is true then return true.
  • If all operands are false returns false.

if( num==2 || num==5) <em> // if num is equal 2 or if num is equal 5</em>

num = num +1; <em>// adds 1 to num.</em>

8 0
3 years ago
Which statement best describes the purpose of the Insert Function dialog box?
ryzh [129]

Answer:

It is used to insert a specific function by selecting it from the Insert Function list.

Explanation:

The insert function list various functions, and we can insert a specific function through a selection of one of the options from the insert function list. And it is certainly not used to display the information according to arguments used in the function, and which is quite clear. Also, it is used to put each type of excel functions in a certain order. And it is also not used to search for any specific functions through any keyword and description. Hence, the correct option is the second option.

3 0
3 years ago
Other questions:
  • A. True
    15·1 answer
  • Allison’s computer is displaying a strange error message saying that Allison, who is an administrator, does not have access to a
    15·1 answer
  • Create a program that asks the user to enter grade scores. Use a loop to request each score and add it to a total. Continue acce
    9·1 answer
  • Theodor is researching computer programming. He thinks that this career has a great employment outlook, so he'd like to learn if
    9·2 answers
  • Which questions should you ask yourself when performing research online?
    9·1 answer
  • Please select the word from the list that best fits the definition
    13·2 answers
  • The network backbone
    11·1 answer
  • Which of the following number is divisible by 3? (340 , 432 , 113)​
    7·1 answer
  • As a result of 5G networks &amp; edge computing there will be an increasing number of different internet connection
    8·1 answer
  • Type the correct answer in the box. Spell all words correctly. Code in which server-side language can be embedded into an HTML d
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!