Need help with Algorithm Workbench Problems 9 and 12 in Starting out with VB 7th
ID: 3787557 • Letter: N
Question
Need help with Algorithm Workbench Problems 9 and 12 in Starting out with VB 7th edition. I usually use Chegg to double-check my answers but these two have me really stuck. Thanks in advance!
9. Write a function named AverageDrop(K) that receives an array of integers and a single integer K. The function returns the average of the array after dropping the K lowest values.
12. Create a function named SumOdds that returns the sum of the elements whose array indexes are odd (we will consider zero to be even).
Explanation / Answer
9.a) First sort the array in ascending
b) Use loop from k to end of array and add all values into sum like
for i=k to size sum=sum+arr[i];
c) avg= sum /(size_of_array - k)
d) return avg
10. Since 1 is neither e ven nor odd and 2 is even we will start from 3
a) Intialize sum to 0
b)Starting i from 3 to end of array
c) if i%2 == 0 then continue;
d) ELSE sum= sum + arr(i);
e) return sum
Dim sum as Integer
For i=3 to size step 1
If i Mod 2 = 0 Then
Continue
Else
sum = sum+ arr(i)
End If
Next i