Write a program that, in a one-dimensional array of 15 elements, counts the number of elements
Write a program that, in a one-dimensional array of 15 elements, counts the number of elements equal to the arithmetic mean.
(Solution provided in Python 3.6.4 programming language)
To begin with, let’s create an empty array, which will then be sequentially filled with elements entered by the user from the keyboard, in the amount of N.
Then, using the for loop, we iterate over all the elements of the array and, thanks to the if condition, determine the number of elements equal to the arithmetic mean. Variable k is a counter of such elements. As a result, we get the following program:
N = int (input ())
a = []
d = 0
k = 0
for i in range (N):
b = int (input ())
a.append (b)
for i in range (N):
d + = a [i]
d / = N
for i in range (N):
if a [i] == d:
k + = 1
print (k)