QUESTION IMAGE
Question
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 a positive integer as a parameter. if the number given to the procedure is no more than 30, the procedure should return the absolute difference between that number and 30. if the number is greater than 30, the procedure should return the number doubled.
examples:
difference30(13) → 17
difference30(46) → 92
difference30(30) → 0
situation c
write a procedure converttobinary that takes an input as a number from 0 to 16 (including 0 but not 16) and converts it to a binary number. the binary number should be returned as a list.
submit
a file (.pdf, .doc, etc.) detailing your responses.
Situation A
Step1: Initialize sum and loop
Set sumOdd to 0. For each number in lotsOfNumbers:
Step2: Check oddness
If number Mod 2 ≠ 0, add number to sumOdd.
Step3: Display result
After loop, output sumOdd.
Pseudocode:
sumOdd = 0
FOR EACH num IN lotsOfNumbers
IF num MOD 2 ≠ 0 THEN
sumOdd = sumOdd + num
END IF
END FOR
DISPLAY sumOdd
Situation B
Step1: Define procedure
Procedure difference30(num):
Step2: Check number range
IF num ≤ 30 THEN
RETURN |num - 30|
ELSE
RETURN num * 2
END IF
Pseudocode:
PROCEDURE difference30(num)
IF num ≤ 30 THEN
result = ABS(num - 30)
ELSE
result = num * 2
END IF
RETURN result
END PROCEDURE
Situation C
Step1: Define procedure and initialize
Procedure ConvertToBinary(num):
binaryList = []
Step2: Handle 0 case
IF num = 0 THEN
binaryList = [0]
Step3: Convert to binary
ELSE
WHILE num > 0
remainder = num MOD 2
PREPEND remainder TO binaryList
num = num // 2
END WHILE
END IF
RETURN binaryList
Pseudocode:
PROCEDURE ConvertToBinary(num)
binaryList = []
IF num = 0 THEN
binaryList = [0]
ELSE
WHILE num > 0
remainder = num MOD 2
binaryList = [remainder] + binaryList
num = num // 2
END WHILE
END IF
RETURN binaryList
END PROCEDURESnap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
s (Pseudocode for each situation):
- Situation A: Pseudocode as above to sum odd numbers.
- Situation B: Pseudocode as above for the difference/double procedure.
- Situation C: Pseudocode as above for binary conversion.