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
What is the name of the domain controller database that windows server 2016 uses to store data about user access and resources o
Inessa05 [86]

The name of the domain controller database that Windows Server 2016 uses to store data about user access and resources on the network is Active Directory.

This Microsoft product manages permissions and access to networked resources. The main service in Active Directory is Domain Services (AD DS), which stores directory information and handles the interaction of the user with the domain.

3 0
3 years ago
If you want to share information with individuals who are internal to your organization, which type of network would you want to
11Alexandr11 [23.1K]

it is globe because I want a successful the all people

8 0
3 years ago
How to copy music from windows media player to pc?
Delvig [45]
<span><span>Click the playlist you want to export, and then click Export Playlist to File on the File menu.
</span><span>In the Save As dialog box, click the folder that contains the playlist you want to export.
</span><span>In the File name box, type a descriptive name for your playlist, and then click OK. This file is saved with a .asx file extension.</span></span>
4 0
3 years ago
______ is a disadvantage of EDI.
Artist 52 [7]

Answer:The number of standards

Explanation:Electronic data interchange (EDI)  is the mechanism through which data is interchanged in the system electronically.It is mostly found in the business field for exchanging of data.

As EDI helps in making message accurate by decreasing the length and also has beneficial features of maintaining the security and increasing productivity ,hence these factor are not considered as the disadvantage .

Too many standard present in the EDI make the working complex by limiting the processing in the small business as compared with large organization.

 

6 0
3 years ago
How could you fact check a news report that you saw on television
Phoenix [80]
I would have to say D) because they know the real answer.

5 0
3 years ago
Other questions:
  • What is life all about?
    15·2 answers
  • Presentation software allows business professionals to _____.
    14·2 answers
  • In the software development life cycle, what is the role of participants in the planning phase? The participants’ role in the pl
    6·1 answer
  • When did the digital revolution begin
    10·1 answer
  • The ________________ command tests connectivity by sending an echo request to a remote computer.
    14·1 answer
  • Edhesive 3.2 Lesson Practice question 1
    5·1 answer
  • C++
    11·2 answers
  • (TCO C) When a remote user attempts to dial in to the network, the network access server (NAS) queries the TACACS+ server. If th
    14·1 answer
  • Please please help I don’t understand
    6·1 answer
  • How many 2/8 pound patties can she make from 7/8 of a pound of hamburger
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!