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
After Lola gave her friend the password to a protected website, her friend was able to remember it only long enough to type it i
Naily [24]

Answer:

Short term memory

Explanation:

Is the capacity an individual has to hold on to a small amount of information for a short period of time without altering it, it is used to remember information like phone numbers, passwords etc. It is also known as primary or active memory.

If short time memories is not rehearsed, they don't last and are easily forgotten, they actually last for about 20-30 seconds.

Aspects of short term memory :

1. Limited capacity : in a short term memory at most 7 items can be stored at a time.

2. Limited capacity : information is short lived and can be lost through distraction and with time.

3. Encoding.

4 0
3 years ago
Saujani describes that women are highly underrepresented in STEM careersShe attributes this to women needing more confidence. Wh
Sedbober [7]

Answer:

have a nice day! ❤❤

Explanation:

5 0
2 years ago
An email message containing a warning related to a non-existent computer security threat, asking a user to delete system files f
LenKa [72]

Answer: Virus Hoax

Explanation:

A computer virus hoax is a message that warns someone of a false virus threat. It is a a chain email that encourages who ever has received the message to pass it to other people as a form of warning.

5 0
2 years ago
A hub transmits all incoming messages to all of its ports except the port where the messages came in. A switch usually sends mes
leonid [27]

Answer:

MAC Addresses (Destination and Source MAC address)

Explanation:

A switch has 3 primary functions:

  • Forward frames
  • Learn addresses
  • Avoid loops

An Ethernet frame has the header, data and trailer and there are two specific fields in the header that helps the switch to know where to send data in future transmissions.

  • destination MAC address
  • source MAC address

every Ethernet frame has this and when the frame hits a switch or any device, any device can look at it ( an Ethernet frame ) and know where it is suppose to go and where it came from.

Every switch has a MAC address table where it stores MAC addresses of different computers on the network.

Example:

When a PC1 sends a frame to PC2 through a switch, the switch looks at the header of the Ethernet frame for the source mac address and adds the source MAC address to its MAC address table and also the port that it came through.

simply put:

A switch looks at the source MAC address to see if it knows it already, if it does. Great! no need to add it again to it's address table.

If it doesn't, it adds it's source address and the port that the frame came from.

This basically how the switch populates its MAC address table.

3 0
3 years ago
Read 2 more answers
In designing a database, a database administrator should consider..
AfilCa [17]
He must consider all of these because the database is the foundation and you Will come to a lot of problems later on in the road if the foundation is faulty
8 0
1 year ago
Read 2 more answers
Other questions:
  • A model release can be either oral or written down. true or false
    11·2 answers
  • Write an application named [LastName]_MultiplicationTable and create a method that prompts the user for an integer value, for ex
    11·1 answer
  • The item that is clicked in a JList can be retrieved using the _____ method of JList.
    8·1 answer
  • When an organization uses cloud computing, they do not have to buy and maintain expensive hardware. Group of answer choices True
    6·1 answer
  • Visit the quick access toolbar to find help when looking for certain commands. True False
    15·2 answers
  • Can you help me, please
    10·1 answer
  • A new attack involves hacking into medical records and then offering these records for sale on the black market. A medical recor
    14·1 answer
  • A(n) ________ will clear all user data and setting changes, returning the device's software to the state it was in when it left
    6·1 answer
  • What type of e-mail typically lures users to sites or asks for sensitive information?
    7·1 answer
  • while determining which antibiotics are best to treat ulcers caused by helicobacter pylori, the drugs used in the experiment are
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!