Given 5 input numbers, the algorithm below should calculate the sum of all the even input...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Given 5 input numbers, the algorithm below should calculate the sum of all the even input numbers. a. Identify what is wrong with the following algorithm. b. How should we fix it? integer i integer array (5) A integer sum i = 0 while (i < 5) A[i] = Get next input i = i + 1 i = 0 sum = 0 while(i < 5) if (A[i] % 2 = 0) sum sum + A[i] i = i + 1 Put sum to output Given 5 input numbers, the algorithm below should calculate the sum of all the even input numbers. a. Identify what is wrong with the following algorithm. b. How should we fix it? integer i integer array (5) A integer sum i = 0 while (i < 5) A[i] = Get next input i = i + 1 i = 0 sum = 0 while(i < 5) if (A[i] % 2 = 0) sum sum + A[i] i = i + 1 Put sum to output
Expert Answer:
Answer rating: 100% (QA)
a Issues with the algorithm The loop index variable i is not initialized before the loop starts It s... View the full answer
Posted Date:
Students also viewed these programming questions
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
do the following,..... Write program that reads a person's first and last names, separated by a space. Then the program outputs last name, comma, first name. Create program that takes in user input...
-
In the same study cited in Example 1, another trial was conducted with 75 women in China given a 100-Yuan bill, while another 75 women in China were given 100 Yuan in the form of smaller bills (a...
-
What are the ethical issues in this situation? Discuss.
-
In a church choir loft, two parallel walls are 5.30 m apart. The singers stand against the north wall. The organist faces the south wall, sitting 0.800 m away from it. To enable her to see the choir,...
-
GDL Enterprises has the following account balances at December 31, 2010. The inventory balance was determined using FIFO. GDL Enterprises has determined that the replacement cost (current market...
-
The following are selected transactions of Lindblom Company. Lindblom prepares financial statements quarterly. Jan. 2 Purchased merchandise on account from Evers Company, $20,000, terms 2/10, n/30....
-
Your supervising attorney is ready to draft a trust for a client. The attorney needs to know which provisions are needed in the trust. Complete the following information. You may create 'make up'...
-
1. Discuss and illustrate how Walmart company formulate its strategies based on/leveraging its core-competencies. 2. Provide and discuss 2 recommendations to enhance the Walmart companys strategy...
-
What are the advantages of electronic data processing in businesses? What have been the disadvantages, especially for auditors?
-
Outline and briefly discuss the types of audit software that may be useful and readily available for the internal auditor. How do these differ in purpose and application from the computer audit tools...
-
What two types of hardware have been helpful to internal auditors?
-
How would you describe the materiality of fraud?
-
Why does management expect internal auditors to be more effective at detecting fraud than external auditors?
-
Write a paper on Leadership and motivation
-
Cleaning Service Company's Trial Balance on December 31, 2020 is as follows: Account name Debit Credit Cash 700 Supplies Pre-paid insurance Pre-paid office rent Equipment Accumulated depreciation -...
-
The hangers support the joist in such a way that the four nails on each hanger can be assumed to support an equal portion of the load. If the joist is subjected to the loading shown, determine the...
-
The hangers support the joist in such a way that the four nails on each hanger can be assumed to support an equal portion of the load. Determine the smallest diameter of the nails at A and B to the...
-
The 60 mm x 60 mm oak post is supported on the pine block. If the allowable bearing stresses for these materials are oak = 43 MPa and pine 25 MPa, determine the greatest load P that can be...
Study smarter with the SolutionInn App