You are given an array with 20 elements. Each element contains an intenger value
ID: 3569516 • Letter: Y
Question
You are given an array with 20 elements. Each element contains an intenger value.
Write a program in pseudo code to display a count of the number of 'even' numbers, and count of the number of 'odd' numbers. Also display a sum of the 'even' numbers and sum and a sum of the 'odd' numbers.
Example Input
15
296
8
195
6625
Example output
The number of even numbers in the array is XXX
The number of odd numbers in the array is XXX
The sum of the even numbers in the array is XXX
The sum of the odd numbers in the array is XXX
Explanation / Answer
=================================================================
BEGIN
DECLARE
INTEGER Array[20]
i=0
evenNumbersCount=0;
oddNumbersCount=0;
sumOfEvenNumbers=0;
sumOfOddNumbers=0;
READ
WHILE[ i LESS THAN 20]
DO
READ Array[i]
i=i+1;
END WHIILE
i=0
WHILE[ i LESS THAN 20]
DO
IF [ Array[i] MODULE EQUAL TO 0]
THEN
evenNumbersCount = evenNumbersCount +1;
sumOfEvenNumbers = sumOfEvenNumbers + Array[i];
ELSE
oddNumbersCount = oddNumbersCount +1;
sumOfOddNumbers = sumOfOddNumbers+Array[i];
END IF
i=i+1;
END WHIILE
PRINT
The number of even numbers in the array is
PRINT
evenNumbersCount
PRINT
The number of odd numbers in the array is
PRINT
oddNumbersCount
PRINT
The sum of the even numbers in the array is
PRINT
evenNumbersCount
PRINT
The sum of the odd numbers in the array is
PRINT
sumOfEvenNumbers
END
=============================================================
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.