Pesudecode base You are given an array with 20 elements. Each element contains a
ID: 666533 • Letter: P
Question
Pesudecode base
You are given an array with 20 elements. Each element contains an integer value.
Write a program in pseudo code to display a count of the number of ‘even’ numbers, and a count of the number of ‘odd’ numbers. Also display a sum of the ‘even’ numbers 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
15
296
8
195
6625
Explanation / Answer
# pseuso code for even number
even_num = 0
for i = 1:length(array):
if (array[i] % 2 == 0):
even_num = even_num + 1;
print "The number of even numbers in the array is "+str(even_num)
# pseuso code for odd number
odd_num = 0
for i = 1:length(array):
if (array[i] % 2 == 0):
odd_num = odd_num + 1;
print "The number of odd numbers in the array is "+str(odd_num)
# pseuso code for sum of even number
even_num = 0
for i = 1:length(array):
if (array[i] % 2 == 0):
even_num = even_num + array[i];
print "The sum of even numbers in the array is "+str(even_num)
# pseuso code for sum of even number
odd_num = 0
for i = 1:length(array):
if (array[i] % 2 == 0):
odd_num = odd_num + array[i];
print "The number of odd numbers in the array is "+str(odd_num)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.