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
BARSIC [14]
3 years ago
7

Assume that you have an array of integers named arr. The following program segment is intended to sum arr [0]through arr[n−1], w

here n = arr.length: sum = 0; i = 0; n = arr.length; while (i != n) { i++; sum += arr[i]; } In order for this segment to perform as intended, which of the following modifications, if any, should be made?
Computers and Technology
1 answer:
Paladinen [302]3 years ago
7 0

Answer:

There is only one modification in the above loop i.e. while loop should be like this--

while (i != n)

     {

         sum+=arr[i];   // Line 1, In question segment it is line 2.

          i++;                // Line 2,  In question segment it is line 1.

     }

Output:

Now if the array input is 1,2,3,4,5 then the output is 15.

Explanation:

In the above question, all the line of the segment is right except the body of the loop because--

  • The First line of the loop is increment statement which increments the value of "i" variable from 1 and the value of "i" variable will be 1 in the first iteration of the loop
  • The second line starts to add the value from 1'st index position of the array. Hence the segment gives the wrong answer. It adds the arr[1] to arr[n-1].
  • So I interchanged both lines of the while loop as shown in the answer part. I make the line 1 (In question segment) as line 2(In answer part) and line 2 (In question segment) as line 1 (In answer part).

Now It gives the correct output because it can add arr[0] to arr[n-1].

You might be interested in
Can be referred to as a universal network of interrelated computers which delivers a very wide variety of information and commun
nlexa [21]

Answer:

Internet

Explanation:

just took the test and got A

7 0
3 years ago
How do you upload photos on this app?
Julli [10]
If you are on mobile when you ask a question there should be a paper clip button, tap it.
6 0
3 years ago
Read 2 more answers
Jill edited James's document using Track Changes. James agrees with all of the edits and wants to incorporate them into his text
OLga [1]
   Hey friends

The answer would be B

              ~Katie

8 0
3 years ago
Read 2 more answers
Emily loves her job as an executive recruiter for a large hospital located in Seattle, Washington. Part of Emily's job requires
Nana76 [90]

Answer:

D. Collective intelligence

Explanation:

Collective intelligence appears when people work together. It is derived  from the collaboration, collective actions, and competition of many parties.

In Emily's job, she collaborate with partners, compare competitors and tap into the knowledge of prospective employees, partners, and customers. Thus, she performs collective intelligence.

3 0
3 years ago
What is an example of a situation in which you might use the append method? In what ways is the append method limited?
Oksanka [162]
If I had an array of the names of people who just walked in the door. I’d append the name of the person who came in next. To update the array.

The append method needs to be looped through to add multiple inputs
5 0
3 years ago
Other questions:
  • In modern computer systems, a byte consists of
    14·1 answer
  • If you are upgrading your operating system to Windows 7, you may not use the In-Place Upgrade Installation Option with
    14·1 answer
  • A hacker has successfully infected an internet-facing server which he will then use to send junk mail, take part in coordinated
    13·1 answer
  • Sarah, a computer user, tells James, a computer technician, that the network she is connected to is running too slowly. Which of
    5·1 answer
  • Uses of the following button in a keyboard: Prt SC, Home, Shift, Tab, Pg Up.​
    6·1 answer
  • Write a couple of paragraph on 'limited government and its important'?​
    7·1 answer
  • Create a class named Console, and move all the methods that retrieve and validate user input to that class. These methods can re
    7·1 answer
  • Within a major students can choose to study a specific area within major. For example a journalism student may study military jo
    8·1 answer
  • 1. provide at least 3 properties and 3 methods of the object computer.
    8·1 answer
  • Write a function that accepts a positive random number as a parameter and returns the sum of the random number's digits. Write a
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!