19.9k views
0 votes
Write pseudocode that demonstrate passes an array of six integers (10, 5, 15, 20, 30, and 25) into three functions called multiple_of_ten(), half(), and sum_and_average(). The multiple_of_ten function should accept a copy of each value in the array and determine whether the value is a multiple of 10. The half function should accept the array and output the first three integers in the array. The sum_and_average function should accept the array and compute the sum and average of all of six integers.

User Jamuhl
by
5.0k points

1 Answer

2 votes

Answer:

multiple_of_ten(x):

eval_x = []

for i in x:

if (i%10) == 0:

eval_x.append('it is multiple of 10')

else:

eval_x.append('it is not multiple of 10')

return eval_x

half(x):

half = len(x)//2

return x[:half]

sum_and_average(x):

sum = 0

for i in x:

sum = sum + i

avg = sum/len(x)

return sum,avg

Step-by-step explanation:

Function multiple_of_ten():

In this function, first you create an empty array in which you will store your results (evaluation messages in this case). Then you evaluate every element of the array in a for loop, by using the modulo operation.

The Modulus is the remainder of the division of one number by another. % is called the modulo operation.

For instance, 10 divided by 5 equals 2 and it remains 0. Any multiple of 10 will get a 0 remainder.

Therefore, every time you apply the modulo operation to an element in the array, and get a zero, you get a message 'it is multiple of 10', and a message 'it is not multiple of 10' otherwise.

Yo store the message you obtain per each number into the empty array you created at the beginning and you return that array as output of the function.

Function half():

In this function, you calculate the length of the array and apply floor division. Floor division returns the quotient(answer or result of division) in which the digits after the decimal point are removed.

For instance, 6 is the length of the array. you divide 6 by 2 and floor division will give you 3 as a result. This floor division will help you when the length of your array is odd.

Finally you return the array from the beginning till the number in the position given by floor division (in our example, 3), as output of the function.

Function sum_and_average():

In this function, you create a variable that will store your sum result. you initialize this variable as 0. then you use a for loop to sum up every element of your array to the variable you created.

Once you sum up all the elements you use that result and divide it by the length of your array in order to calculate the average.

Finally you return both the sum and the average as outputs of the function.

User Jonny Asmar
by
5.7k points