Lists and Procedures Pseudocode Practice For each situation, provide a pseudocoded algorithm that would accomplish the task. Make sure to indent where appropriate. Situation A Write a program that: Takes the list lotsOfNumbers and uses a loop to find the sum of all of the odd numbers in the list (hint: use Mod). Displays the sum. Situation B Write a procedure that takes

Respuesta :

Answer:

The pseudocoded algorithm is as follows:

Procedure sumOdd(lotsOfNumbers):

    oddSum = 0

    len = length(lotsOfNumbers)

    for i = 0 to len - 1

         if lotsOfNumbers[i] Mod 2 != 0:

              OddSum = OddSum + lotsOfNumbers[i]

Print(OddSum)

Explanation:

This defines the procedure

Procedure sumOdd(lotsOfNumbers):

This initializes the oddSum to 0

    oddSum = 0

This calculates the length of the list

    len = length(lotsOfNumbers)

This iterates through the list

    for i = 0 to len-1

This checks if current list item is odd

         if lotsOfNumbers[i] Mod 2 != 0:

If yes, the number is added to OddSum

              OddSum = OddSum + lotsOfNumbers[i]

This prints the calculated sum

Print(OddSum)