Question: Given 5 input numbers, the algorithm below should calculate the sum of all the even input numbers. a. Identify what is wrong with the

Given 5 input numbers, the algorithm below should calculate the sum of

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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

a Issues with the algorithm The loop index variable i is not initialized before the loop starts It s... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!